why are some of my lines yellow andd some white
-
- Posts: 50
- Joined: May 19th, 2012, 3:00 pm
why are some of my lines yellow andd some white
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 );
}
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 );
}
Re: why are some of my lines yellow andd some white
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.
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.
ʕ •ᴥ•ʔ
-
- Posts: 50
- Joined: May 19th, 2012, 3:00 pm
Re: why are some of my lines yellow andd some white
this is my code
- zentojamorn
- Posts: 10
- Joined: May 22nd, 2012, 4:22 am
Re: why are some of my lines yellow andd some white
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).
You should use PutPixel(x,y,r,g,bl) instead of PutPixel(x,y,r,g,b).
Sorry for my poor english..
Re: why are some of my lines yellow andd some white
It's a weird bunch of files you uploaded...
Yup. Currently your code is saying that the color has to be: PutPixel(red, green, *line equation*)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).
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
ʕ •ᴥ•ʔ
Re: why are some of my lines yellow andd some white
Hehe, this is why I always ask people to post their entire solution. 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.
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
-
- Posts: 50
- Joined: May 19th, 2012, 3:00 pm
Re: why are some of my lines yellow andd some white
Thanks
very much guys
mission success hope it works
very much guys
mission success hope it works
-
- Posts: 50
- Joined: May 19th, 2012, 3:00 pm
Re: why are some of my lines yellow andd some white
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
help please
Re: why are some of my lines yellow andd some white
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
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
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk