Tuesday, July 04, 2006

Testing OpenGL

This post is a follow on from my previous post on installing OpenGL. Copy and paste the following code into your C++ app to test drawing a pretty pattern with OpenGL!

------------------------------------------

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

#define WINDOW_WIDTH GetSystemMetrics(SM_CXSCREEN)
#define WINDOW_HEIGHT GetSystemMetrics(SM_CYSCREEN)

void Display(void);

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

glutInit(&argc, argv);

glutInitWindowSize( WINDOW_WIDTH, WINDOW_HEIGHT );
glutInitWindowPosition( 0, 0 );
glutCreateWindow(\"Testing OpenGL Installation\");

glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );

glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glShadeModel(GL_FLAT);
glOrtho( 0.0, 1.0 , 0.0, 1.0, -1.0, 1.0 );

glClearColor(0.0, 0.0, 0.0, 0.0);

glutDisplayFunc(&Display);

glutMainLoop();

return 0;
}

void Display(void){

GLdouble i = 0.0;
GLdouble MAX = 1.0;

glClear(GL_COLOR_BUFFER_BIT);
glColor3f( (GLfloat)1.0, (GLfloat)0.01, (GLfloat)0.23);

for( i=0.0; i<=MAX; i += 0.001){
glBegin(GL_LINES);
glVertex2f(0, MAX-i);
glVertex2f(i, 0);
glEnd();

glutSwapBuffers();
}

glColor3f( 1.0, 1.0, 0.23);

for( i=0.0; i<=MAX; i += 0.1){
glBegin(GL_LINES);
glVertex2f(0, MAX-i);
glVertex2f(i, 0);
glEnd();

glutSwapBuffers();
}

glFlush();
}

0 Comments:

Post a Comment

<< Home