Wasiim Ouro-sama
Wasiim Ouro-sama

Reputation: 1565

OpenGL glRectf() not displaying

glRectf() is not being displayed inside my window:

#include <GL/gl.h>
#include <GL/glut.h>

void renderScene(){
    glClearColor(0.0f,1.0f,1.0f,1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0f,0.0f,0.0f);
    glRectf(225.0f,150.0f,150.0f,100.0f);
    glFlush();
}

int main(int argc, char*argv[]){
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
    glutInitWindowSize(450, 350);
    glutCreateWindow("My first OpenGL Program...took forever");
    glutDisplayFunc(renderScene);
    glutMainLoop();
    return 0;
}

Upvotes: 1

Views: 2314

Answers (1)

genpfault
genpfault

Reputation: 52082

(225.0f,150.0f) is nowhere near the identity frustum.

Supply some appropriate transform matrices so your rectangle doesn't get clipped:

#include <GL/glut.h>

void renderScene()
{
    glClearColor(0.0f,1.0f,1.0f,1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( -300, 300, -300, 300, -1, 1 );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    glColor3f(1.0f,0.0f,0.0f);
    glRectf(225.0f,150.0f,150.0f,100.0f);

    glFlush();
}

int main(int argc, char*argv[])
{
    glutInit( &argc, argv );
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
    glutInitWindowSize(450, 350);
    glutCreateWindow("My first OpenGL Program...took forever");
    glutDisplayFunc(renderScene);
    glutMainLoop();
    return 0;
}

Upvotes: 2

Related Questions