View Full Version : how use "glGetString(GL_VERSION)" ?

05-10-2003, 03:48 AM
to know the version i'm using,
please http://www.opengl.org/discussion_boards/ubb/biggrin.gif

[This message has been edited by airseb (edited 05-10-2003).]

05-10-2003, 05:20 AM
char *version = (char*)glGetString(GL_VERSION);

05-10-2003, 06:39 AM
i have a problem, i do this :

#include <gl\GLAUX.h>
#include <gl\glut.h>
#include <gl\gl.h>
#include <gl\glext.h>
#include <iostream.h>

void main ()
char *version = (char*)glGetString(GL_VERSION);
cout <<*version<<endl ;

and windows say to me that the program have to close :-(
what's wrong ?

05-10-2003, 07:32 AM
You have to create a rendering context for any OpenGL function to work.

05-10-2003, 07:36 AM
can you explain me more ?
does it mean that i have to put "char *version = (char*)glGetString(GL_VERSION);" in the display function ? with a cout ?

Brian Jones
05-10-2003, 07:43 AM
airseb, I showed you how to use this function. If you don't know anything about typecasting you should spend sometime learning C++. Typecasting is operation of turning one type into another. glGetString returns a null terminated string of type const unsigned char*. You can do this:

const unsigned char* glver = glGetString(GL_VERSION);

cout << glVer << endl; // DO NOT PUT A DEREFERENCE OPERATOR infront of glVer

Brian Jones
05-10-2003, 07:46 AM
Originally posted by Bob:
You have to create a rendering context for any OpenGL function to work.

What Bob means is you should have OpenGL "initialized" before using any OpenGL functions

05-10-2003, 07:49 AM
GL is initialized only when you have a window opened by your program. So, you cannot access GL in console mode unless you pop up a window.

I guess you are a very beginner. Try GLUT or maybe, even better, go for SDL.
Read the help, see some tutorials on how to pop up a win.

Once you pop up your gl-enabled window (no matter how you do it), you can call all the GL functions from everywhere. You can put it in the main or in the messageProc or in a Render() function.

Little note about your cout:
char *string = "This is a string";

Program output is -->T<-- and not -->This is a string<--.

This is becouse *string is a char and not a char* so, when cout will process it it will recognize it as a char and output it. I guess you should have to recheck your pointer math and priorities. Understand pointers, they are important in GL and I find them often useful.

EDIT: hey, while typing the message, other messages popped up before this! Woah...

[This message has been edited by Obli (edited 05-10-2003).]

05-11-2003, 03:27 AM
ok it works ! http://www.opengl.org/discussion_boards/ubb/biggrin.gif
thanks everybody http://www.opengl.org/discussion_boards/ubb/biggrin.gif

05-11-2003, 03:32 AM
sorry brian of having done a new topic for that but i didn't know that an open gl window had to be opened before GL_VERSION.

[This message has been edited by airseb (edited 05-11-2003).]