NO

Author Topic: Getting Started with OpenGL GLUT  (Read 7729 times)

Trajecto

  • Guest
Getting Started with OpenGL GLUT
« on: February 25, 2006, 05:38:44 PM »
GLUT is the OpenGL Utility Toolkit. GLUT is good for learning OpenGL since it is platform independent, and you don't have to worry about Windows programming. The same program should compile under Windows, Linux, UNIX, etc. GLUT applications compile as console applications so you can jump right in and start trying things out. The only drawback of course is no windows components such as menus, buttons, etc. you can still however use the keyboard, a mouse, a joystick, etc. for user input.

Since GLUT is platform independent the natural language to choose is ANSI C, and for Windows of course, Pelles C. In this tutorial I will show you how to set up Pelles C for programming in GLUT and also show some sample code.

Before you begin you will need the GLUT header and library files, glut32.lib, glut.lib and glut.h. I have a download available here that my code samples are tested with:
http://www.trajectorylabs.com/OpenGL/GLUT.ZIP
These files are from the OpenGL SuperBible book 3rd Edition CD. The very latest Win32 GLUT files can be found here:
http://www.xmission.com/~nate/glut.html My code however is not guaranteed to work with anything other than the files I have supplied.

Once you  have downloaded the header and library files add them to the proper Pelles C directories as shown:
PellesC\Lib\Win\glut32.lib
PellesC\Lib\Win\glut.lib
PellesC\Include\Win\gl\glut.h

Now fire up Pelles C and start a new Win32 program (EXE) as a new workspace. Select  File - New - Source code and paste the code below.

/**********************************************************************/
/******************************************/
/* A Very Simple OpenGL Example          */
/******************************************/

/* Draws a simple window with a rectangle in it */

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

void init(void);
void display(void);

int main (int argc, char **argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
   glutInitWindowSize(250, 250);
   glutInitWindowPosition(100, 100);
   glutCreateWindow("My First OpenGL Application");
   init();
   glutDisplayFunc(display);
   glutMainLoop();
   return 0;
}

void init(void)
{
   glClearColor(0.0, 0.0, 0.0, 0.0);
   glColor3f(0.0, 0.0, 1.0);
   glMatrixMode(GL_PROJECTION);   
   glLoadIdentity();
   glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0);
}

void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   glRectf(-5.0, 5.0, 5.0, -5.0);
   glutSwapBuffers();
}
/**********************************************************************/


Now save the code as myfirst.c and add it to your project. We are almost done.  Under Project - Project Options - Linker - Library and object files add glut32.lib and glut.lib. Under Subsystem Type select Console. Under Compiler - Calling convention select __cdecl. Do a File Save all.

Under Project, Compile, Build then Execute. You should have a beautiful black screen with a blue square on it!



Enjoy!
-Trajecto

kobold

  • Guest
Getting Started with OpenGL GLUT
« Reply #1 on: February 26, 2006, 06:55:22 PM »
You know that Glut will not be developed any further?
By the way, i am searching for an alternative to the "glulookat".

Trajecto

  • Guest
Getting Started with OpenGL GLUT
« Reply #2 on: February 26, 2006, 11:10:34 PM »
I did not know that. It is almost a relief knowing it will not change!

I mispoke above and edited the part that said no user interaction is possible.  This is not true, you can poll the mouse, keyboard, joystick, etc. for user input.

Trajecto

  • Guest
Getting Started with OpenGL GLUT
« Reply #3 on: February 28, 2006, 04:06:54 AM »
I'm adding alot more to the OpenGL GLUT tutorials, graphics, explaining how things work, etc., over here:

http://www.trajectorylabs.com/opengl.html

Eventually I will add Windows programming and the loading of 3D models.

Trajecto

  • Guest
Getting Started with OpenGL GLUT
« Reply #4 on: March 23, 2006, 07:02:56 AM »
OpenGL Collected Source Code for Pelles C Added

http://www.trajectorylabs.com/OpenGL_source_code.html

Enjoy!