• Create Account

#ActualGDsnakes

Posted 15 January 2013 - 06:19 PM

class QuadDrawing {
private:

public:
void Draw();
};

{
}

{
glPushMatrix();
//Set color
glColor4f(1.0,0.0,0.0,0.0);

glVertex2f(90.0,50);
glVertex2f(90.0,-80);
glVertex2f(0.0,-80);
glVertex2f(0.0,50);

glEnd();

glPopMatrix();

}

int main( int argc, char *argv[] )
{
//Quit flag
bool quit = false;

//Initialize
if( init() == false )
{
return 1;
}

//The frame rate regulator
Timer fps;
Drawing Square1(300.0, 300.0);
int x = 0, y = 0;
//Wait for user exit
while( quit == false )
{
//Start the frame timer
fps.start();

//While there are events to handle
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_QUIT )
{
quit = true;
}

else if( event.type == SDL_KEYDOWN )
{
//Handle keypress with current mouse position

SDL_GetMouseState( &x, &y );

handleKeys (event.key.keysym.unicode. x. y);

}
}

Square1.Draw();

update();

//Cap the frame rate
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
}
}

//Clean up
clean_up();

return 0;
}



The problem is I want to draw a square to test the class I made which should just take two floating point numbers and draw a square at those points, but the square is never drawn...instead the window comes up but stays completely blank. The window was even clear (no clear color) so I thought that was the problem and added glClear( GL_COLOR_BUFFER_BIT ); to the Draw function in the class making it...

void QuadDrawing::Draw()
{

glClear( GL_COLOR_BUFFER_BIT);

glPushMatrix();
//Set color
glColor4f(1.0,0.0,0.0,0.0);

glVertex2f(90.0,50);
glVertex2f(90.0,-80);
glVertex2f(0.0,-80);
glVertex2f(0.0,50);

glEnd();

glPopMatrix();

}



Still didn't work and the window come up clear/blank (not even the clear color).

But the thing is if I just make it a function and not a class and pass the floating X/Y to draw the square there it works fine. So its a problem with the class.

#1GDsnakes

Posted 15 January 2013 - 03:43 PM

private:

public:
void Draw();
};

{
}

{
glPushMatrix();
//Set color
glColor4f(1.0,0.0,0.0,0.0);

glVertex2f(90.0,50);
glVertex2f(90.0,-80);
glVertex2f(0.0,-80);
glVertex2f(0.0,50);

glEnd();

glPopMatrix();

}

int main( int argc, char *argv[] )
{
//Quit flag
bool quit = false;

//Initialize
if( init() == false )
{
return 1;
}

//The frame rate regulator
Timer fps;
Drawing Square1(300.0, 300.0);
int x = 0, y = 0;
//Wait for user exit
while( quit == false )
{
//Start the frame timer
fps.start();

//While there are events to handle
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_QUIT )
{
quit = true;
}

else if( event.type == SDL_KEYDOWN )
{
//Handle keypress with current mouse position

SDL_GetMouseState( &x, &y );

handleKeys (event.key.keysym.unicode. x. y);

}
}

Square1.Draw();

update();

//Cap the frame rate
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
}
}

//Clean up
clean_up();

return 0;
}

The problem is I want to draw a square to test the class I made which should just take two floating point numbers and draw a square at those points, but the square is never drawn...instead the window comes up but stays completely blank. The window was even clear (no clear color) so I thought that was the problem and added glClear( GL_COLOR_BUFFER_BIT ); to the Draw function in the class making it...

{

glClear( GL_COLOR_BUFFER_BIT);

glPushMatrix();
//Set color
glColor4f(1.0,0.0,0.0,0.0);

glVertex2f(90.0,50);
glVertex2f(90.0,-80);
glVertex2f(0.0,-80);
glVertex2f(0.0,50);

glEnd();

glPopMatrix();

}

Still didn't work and the window come up clear/blank (not even the clear color).

But the thing is if I just make it a function and not a class and pass the floating X/Y to draw the square there it works fine. So its a problem with the class.

PARTNERS