GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Saturday, February 26, 2011

OpenGL - Draw Rectangle

Here's a code on how to make backgrouning color:

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

void setup(){
   glClearColor(1.0f, 0.0f, 0.0f, 0.0f);    // backgrouning
}

void display(){

   glClear(GL_COLOR_BUFFER_BIT);
   glColor3f(0.0f, 0.0f, 0.0f);    // coloring rect
   glRectf(-0.75f, 0.75f, 0.75f, -0.75f);  // draw rect
   glFlush();
   glutSwapBuffers();
}

int main(int argc, char *argv[]){

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowSize(400, 300);    // horizontal, vertical
    glutInitWindowPosition(200, 100);    // horizontal, vertical
    glutCreateWindow("Hello World");    // title of the window

    glutDisplayFunc(display);
    glutMainLoop();

    return 0;
}



Share/Bookmark

1 comment: