PDA

View Full Version : Should i use GLUT?



02-18-2002, 10:37 AM
I have been following NEHE tutorials but he uses this glaux.dll which i cant use because i have dev c++ which uses mingw compiler. I have also read it is obselete. Because i am just starting out i am confused as to what sdk's i should have. All these different wrapper api's are doing my head in. Just understanding how to open window under win32 is a nightmare! Can someone point me in the right direction and get me started properly BTW i dont want to download 130mb dx sdk

nexusone
02-18-2002, 10:48 AM
Yes you should use GLUT for the following reason's.
1. I don't think there is a compiler that does not have lib support for it.
2. It is supported by multiple platforms, Windows, Linux, Mac.
3. Makes creating windows easy.
4. nehe also has glut versions of most of his examples.

An example of opening a OpenGL window with glut. This little bit of program will open a window using glut library. Use the [ESC] key to exit.

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

void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
default:
break;
}

}

void reshape (int w, int h)
{
// Window size has changed stuff goes here.
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
}

void display(void)
{

//GL drawing stuff here.

}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
glutSetWindowTitle("Glut window");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}


Originally posted by Cipher:
I have been following NEHE tutorials but he uses this glaux.dll which i cant use because i have dev c++ which uses mingw compiler. I have also read it is obselete. Because i am just starting out i am confused as to what sdk's i should have. All these different wrapper api's are doing my head in. Just understanding how to open window under win32 is a nightmare! Can someone point me in the right direction and get me started properly BTW i dont want to download 130mb dx sdk



[This message has been edited by nexusone (edited 02-18-2002).]

Shag
02-18-2002, 03:01 PM
You shouldn't use glut for the following reasons.

1. Any compiler supports native OS calls.
2. OpenGL is supported natively on most OS's
3. Hides window creation. Therefore stops the user from understanding the OS.
4. Relying of other peoples samples isn't the way forward. Especially when the tutor doesn't understand the basic OS window creation functions.

[This message has been edited by Shag (edited 02-18-2002).]

[This message has been edited by Shag (edited 02-18-2002).]

nexusone
02-19-2002, 06:25 AM
Glut save's you the trouble of having to rewrite all the window functions when you want to port it say from Windows to linux or Mac.

And why should one have to learn the window creation for every OS, when you can use GLUT and it works for all of them.


Originally posted by Shag:
You shouldn't use glut for the following reasons.

1. Any compiler supports native OS calls.
2. OpenGL is supported natively on most OS's
3. Hides window creation. Therefore stops the user from understanding the OS.
4. Relying of other peoples samples isn't the way forward. Especially when the tutor doesn't understand the basic OS window creation functions.

[This message has been edited by Shag (edited 02-18-2002).]

[This message has been edited by Shag (edited 02-18-2002).]



[This message has been edited by nexusone (edited 02-19-2002).]

marcus256
02-19-2002, 06:37 AM
Maybe you have not noticed, but there is now a forum for these things...

Shag, if you do it that way, it will be VERY difficult to get along with porting your code to any other OS. You usually get very stuck in one environment once you get to deep... Have you ever written anything for Linux? Solaris?

Hiding window creation can be a good thing, at least in the beginning. Personally, I prefer to write it once and then forget about it. What is better: to know how one OS works, or the basics for most OSes? You will not understand the basic concepts of an OS if you do not know several OSes. How do you learn that?

Let's face it. Creating windows is not everything. Once you want to get down and dirty, you may have to do it. But then compare different OSes - that usually helps alot.

Ok, I recommend GLFW instead of GLUT. Check it out: http://hem.passagen.se/opengl/glfw/ It has nice docs, some examples, it's easy to use, it's portable, and IF you want to learn how to open a Window, read the source...

Here is the same example as above (for GLUT), but with GLFW:



#include <GL/glfw.h>
#include <stdlib.h>

int main( int argc, char **argv )
{
int running, w, h;

// Init GLFW and open window
glfwInit();
if( !glfwOpenWindow( 500,500, 0,0,0,0, 0,0, GLFW_WINDOW ) )
{
glfwTerminate();
return 0;
}
glfwSetWindowPos( 100, 100 );
glfwSetWindowTitle( "My OpenGL window" );

// Main loop
do
{
// Camera setup goes here
glfwGetWindowSize( &amp;w, &amp;h );
glViewport( 0, 0, w, h );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();

//GL drawing stuff here.

// Swap buffers
glfwSwapBuffers();

// Check for escape key and if window is still opened
running = !glfwGetKey( GLFW_KEY_ESC ) &amp;&amp;
glfwGetWindowParam( GLFW_OPENED );
}
while( running );

glfwTerminate();
return 0;
}


That program compiles to 15 KB (including GLFW, which is statically linked into the app - no DLL needed)

Oh yes, GLFW does not work for Macs (yet?), but it does work for Windows and X11 (e.g. Linux, Solaris etc).


[This message has been edited by marcus256 (edited 02-19-2002).]

golgi apparatus
02-20-2002, 01:28 AM
Windows have nothing to do with the O/S. If they do, explain to me the relationship between a window and the Unix kernel...

glFanatic
02-20-2002, 01:58 AM
the best thing to do is staying cross-platform as much as possible imo. Glut isnt bad, works well actually. Only thing that I have a problem with is the way it polls the keyboard state. Is there a way to actually poll Key up and key down states seperatly in glut?

marcus256
02-21-2002, 04:49 AM
Originally posted by glFanatic:
Is there a way to actually poll Key up and key down states seperatly in glut?

With GLFW there is http://www.opengl.org/discussion_boards/ubb/smile.gif

When you get your keyboard event from GLFW it comes with a flag saying "pressed" or "released", so you can trigger on either of the events (or both).

You also have the "manual" polling method with glfwGetKey(), which queries the status of an individual key (see program example a few posts earlier).


golgi apparatus,

I believe that it's because the X Window System was added on top of Unix to remedy the lack of a graphical user interface. When "modern" OSes were designed, they integrated the Windowing system into the OS ("You can't have one without the other" - Frank Sinatra). I think that the X solution is really the neatest solution, and the neatest windowing system too! For instance if I run an X-server under Windows (yes, you can do that) I can run an OpenGL application on e.g. a Solaris station over the net and have the window appear on my Windows-based computer (using the acceleration on my local computer!). Can you do that natively with sucky MS Windows? http://www.opengl.org/discussion_boards/ubb/tongue.gif



[This message has been edited by marcus256 (edited 02-21-2002).]

zeraiam
02-21-2002, 08:26 AM
Is there a way to actually poll Key up and key down states seperatly in glut?


You can use glutKeyboardFunc for key press and glutKeyboardUpFunc for key release (maybe you need the latest version).

02-24-2002, 11:33 AM
Thanks for the link, glfw is what I'v been looking for.

I'll take a look at it http://www.opengl.org/discussion_boards/ubb/smile.gif

02-24-2002, 09:35 PM
try sdl from www.libsdl.org. (http://www.libsdl.org.)

they have sound and other apis ie networking and it is cross-platform. and yeah u can use opengl within their graphic context. not yet full blown but better than using propietary api. http://www.opengl.org/discussion_boards/ubb/smile.gif