Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualGDsnakes

Posted 15 January 2013 - 06:19 PM

class QuadDrawing {
private:
    float QuadoffX;
    float QuadoffY;
    

public:
    QuadDrawing(float, float);
    void Draw();
};

QuadDrawing::QuadDrawing( float Xoff, float Yoff)
{
    Xoff = QuadoffX;
    Yoff = QuadoffY;
}

void QuadDrawing::Draw()
{
    glPushMatrix();
    glTranslatef(QuadOffX,QuadoffY,0.0f);
    glBegin(GL_QUADS);
    //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);
                
                }
        }

    MenuState();
    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();
    glTranslatef(QuadOffX,QuadoffY,0.0f);
    glBegin(GL_QUADS);
    //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

class QuadDrawing {
private:
    float QuadoffX;
    float QuadoffY;
    

public:
    QuadDrawing(float, float);
    void Draw();
};

QuadDrawing::QuadDrawing( float Xoff, float Yoff)
{
    Xoff = QuadoffX;
    Yoff = QuadoffY;
}

void QuadDrawing::Draw()
{
    glPushMatrix();
    glTranslatef(QuadOffX,QuadoffY,0.0f);
    glBegin(GL_QUADS);
    //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);
                
                }
        }

    MenuState();
    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();
    glTranslatef(QuadOffX,QuadoffY,0.0f);
    glBegin(GL_QUADS);
    //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