PDA

View Full Version : GL Program Crashing........



caesar868
08-16-2000, 12:45 PM
Hi, I'm getting started with OpenGL coding, and right now I'm working in MS Win 98. I'm using MSVC++ 6 for my compiler.
Here's the problem. I have this really basic program, it's an example from a text. When I compile it with g++ in linux, it works fine. I can compile and build it in windows also. But when I go to exectue the program, it gives me this error message:

"This Program has performed an illegal operation and will be shut down. If the problem persists, contact the program vendor". And the details, "OPENGLTESTS caused an invalid page fault in module GLUT32.DLL at 0167:10005456"

I was wondering, was it my program, the OpenGL libraries, or the OpenGL headers?

The book I'm reading is "OpenGL Prorraming Guide, 3rd Edition" by the OpenGL ARB, and it has about 4 authors. Any suggestions?? Thanks for your time.

--Bryan

Gorg
08-16-2000, 04:17 PM
You are doing something wrong. Probably missing a callback or something. Could you show us the init code?

caesar868
08-16-2000, 08:34 PM
Here's the code from the book:
#include <stdlib.h>
#include <GL/glut.h>

static GLfloat spin = 0.0;

void init(void){
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
}

void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glRectf(-25.0, -25.0, 25.0, 25.0);
glPopMatrix();
glutSwapBuffers();
}

void spinDisplay(void){
spin = spin + 2.0;
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay();
}

void reshape(int w, int h){
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0,
50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void mouse(int button, int state,
int x, int y){
switch(button){
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN){
glutIdleFunc(spinDisplay);
}
break;
case GLUT_MIDDLE_BUTTON:
if (state == GLUT_DOWN){
glutIdleFunc(NULL);
}
break;
default:
break;
}
}

int main(int &argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}

wellsk
08-16-2000, 10:49 PM
Your main function doesn't seem to be correct. If you are compiling the file as a C++ file, this may compile without errors. Try changing the file to a C file (just reset the extension) and recompiling or remove the C++ reference designator in the main argc argument. Try:

int main (int argc, char *argv[])
instead.

Kv

warlordQ
08-17-2000, 06:26 AM
That main function is correct.... It should work as it is....... But there is a global thing losing it's contents somewhere...

hmm try doing this..... make all your functions static........

static void init( void )
static void display( void )
static void spinDisplay( void )
static void reshape( int w, int h )
static void mouse( int button, int state, int x, int y )

And leave your main as is....

That should fix it up.... If that dosn't work, then it could be your drivers....
Let me know if it fixes anything up.....

caesar868
08-17-2000, 06:41 AM
I tried both options, and got the same results, so it's probably my drivers and libraries?? The GL drivers came with Win98, and I got Glut from Nate Robbins website. I will try to install the libraries and headers again, just in case. Thanks for your help, I greatly appreciate it.

warlordQ
08-17-2000, 06:00 PM
Your OpenGL Video card drivers..... What video card do you have ??

caesar868
08-17-2000, 06:27 PM
I have an nVidia Riva TNT card...does it support GL?

warlordQ
08-18-2000, 02:15 AM
Yeah you must have the buggy drivers......

Goto http://www.nvidia.com/

And download new drivers.... It will install OpenGL 1.2 also... That might fix things ups a bit.....