Wednesday, August 23, 2006

Tutorials

This site looks good for getting started

http://www.euclideanspace.com/software/games/twod/openglcpp/index.htm

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();
}

Getting Started!

Ok, so today I started out looking into using the open source "OpenGL" graphics library with Visual C++, using visual studio.NET as a working environment (although much of this will apply to other compilers not just msbuild).

As standard, the 2 openGL libraries are installed automatically with Visual C++ and can be found along with all the other libraries in,

%Visual Studio Directory%/VC/PlatformSDK/Lib

the two libraries are

opengl32.lib
glu32.lib

The next step is to install GLUT, a set of libraries to use in addition to OpenGL

http://www.xmission.com/~nate/glut.html

In the downloadable archive you will find 3 files, a library, a dll and a header file.

The dll (glut32.dll) must be placed in your system directory (windows/system) , and/or in the running folder of your application (should you pass it on to a friend)

the library (glut32.lib) must go in the lib folder alongside the opengl32.lib file (mentioned earlier)

the header file (glut.h) must go in....


%Visual Studio Directory%/VC/PlatformSDK/Include/gl/

At this stage the system is ready to make an OpenGL application. Open Visual Studio and make a new empty C++ console32 application. Head straight to the properties of the project and change the drop down menu to All Configurations. Now click Linker > Input on the left tree node, and add in the three libraries we need to include with our project (in the additional dependencies field)

opengl32.lib glu32.lib glut32.lib

you can now start writing some c++, make a new test.c document and make sure to include the header file.

#include <gl/glut.h>

make an int main() function and test building your project. If any troubles occur follow this comprehensive guide.

http://csf11.acs.uwosh.edu/cs371/visualstudio/#step1

CONGRATULATIONS!!! That may have seemed a lengthy process but the majority of it only needs to be done once.

NB: Remember to include glut32.dll with all your deployments!