why are some of my lines yellow andd some white

The Partridge Family were neither partridges nor a family. Discuss.
kacper130320
Posts: 50
Joined: May 19th, 2012, 3:00 pm

why are some of my lines yellow andd some white

Post by kacper130320 » May 20th, 2012, 9:17 pm

when i draw some lines

game cpp (lesson 12 )

#include "Game.h"

Game::Game( HWND hWnd,const KeyboardServer& kServer )
: gfx ( hWnd ),
kbd( kServer )
{}
void Game::Go()
{
gfx.BeginFrame();
ComposeFrame();
gfx.EndFrame();
}

void Game::DrawGrid( int x,int y )
{
gfx.DrawLine( 0 + x,99 + y,299 + x,99 + y,255,255,255 );

gfx.DrawLine( 0 + x,199 + y,299 + x,199 + y,255,255,255 );

gfx.DrawLine( 99 + x,0 + y,99 + x,299 + y,255,255,255 );

gfx.DrawLine( 199 + x,0 + y,199 + x,299 + y,255,255,255 );

}

void Game::ComposeFrame()
{
DrawGrid(300,150 );
}

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: why are some of my lines yellow andd some white

Post by LuX » May 21st, 2012, 10:29 am

The code looks fine. Try to update your graphics card, info should be found on the website of the graphics card.

OR upload the project here, so we can look if the problem replicates with other people, otherwise its a local problem on your computer as I mentioned.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: why are some of my lines yellow andd some white

Post by chili » May 21st, 2012, 10:35 am

What LuX said. ;)
Chili

kacper130320
Posts: 50
Joined: May 19th, 2012, 3:00 pm

Re: why are some of my lines yellow andd some white

Post by kacper130320 » May 22nd, 2012, 6:41 am

Chili DirectX Framework - Kopia.rar
(5.36 MiB) Downloaded 173 times
this is my code

User avatar
zentojamorn
Posts: 10
Joined: May 22nd, 2012, 4:22 am

Re: why are some of my lines yellow andd some white

Post by zentojamorn » May 22nd, 2012, 11:41 am

Problem is in DrawLine function. Your variable name is misleading.
You should use PutPixel(x,y,r,g,bl) instead of PutPixel(x,y,r,g,b).
Sorry for my poor english..

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: why are some of my lines yellow andd some white

Post by LuX » May 22nd, 2012, 2:12 pm

It's a weird bunch of files you uploaded...
Problem is in DrawLine function. Your variable name is misleading.
You should use PutPixel(x,y,r,g,bl) instead of PutPixel(x,y,r,g,b).
Yup. Currently your code is saying that the color has to be: PutPixel(red, green, *line equation*)

Code: Select all

float m = (float)dx / (float)dy;
		float b = x1 - m*y1;                            // <--- note that "b" is declared as line equation
		for( int y = y1; y <= y2; y++ )
				{
					int x = m*y + b + 0.5f;
					PutPixel( x,y,r,g,b  );    // "b" is still line equation here
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: why are some of my lines yellow andd some white

Post by chili » May 22nd, 2012, 3:13 pm

Hehe, this is why I always ask people to post their entire solution. :roll: Very often the problem is not the part of the code that they copy and paste into their post.

As the guys above me pointed out, your b variable for the blue component is getting covered up by your b variable for the y-intercept of your straight line equation. You need to rename one of them, preferably the one for the blue component (which is what I do in the tutorial video if you look closely).

Good job guys in catching his error. :)
Chili

kacper130320
Posts: 50
Joined: May 19th, 2012, 3:00 pm

Re: why are some of my lines yellow andd some white

Post by kacper130320 » May 22nd, 2012, 4:53 pm

Thanks
very much guys
mission success hope it works

kacper130320
Posts: 50
Joined: May 19th, 2012, 3:00 pm

Re: why are some of my lines yellow andd some white

Post by kacper130320 » May 22nd, 2012, 7:36 pm

oh yeah and my other bug was in game.cpp when i tried to draw the X it said that it dosent recognise the "gfx." the code was gfx.DrawLine()
help please

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: why are some of my lines yellow andd some white

Post by Asimov » May 23rd, 2012, 12:18 am

Hi kacper,

I have never had the problem using gfx.DrawLine in the main game.cpp.

The only time I had a problem was when I tried to make a function in game.cpp.

I called it

void star()
{
}

instead of

void Game::star()
{
}

Just a beginners mistake.
I wonder if that is your problem. If you don't define which Class the function is for I think it loses scope.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

Post Reply