PDA

View Full Version : Need a little help here...



tosomnic
10-11-2002, 08:14 PM
Hi. I'm learing OpenGL programming at university and I need a little help (I'd ask the prof but he's not used to my prog environment...). I'm running WinXP with MS VC++ 6.0. I have downloaded service pack 5.0 for VC++ and have the (apparently) most up-to-date OpenGL drivers.
I've been attempting to make a very simple program (named funct). According to my textbook, all my code is correct, and the compiler gives no errors. Whenever I run it, however, I receive a "Unhandled exception in funct.exe (GLUT32.DLL): 0xC0000005: Access Violation." error message and in the debug window it says "First-chance exception in funct.exe (GLUT32.DLL): 0xC0000005: Access Violation.". I've figured out that the error occurs whenever I try to set a callback function (via glutDisplayFunc(myDisplay) or glutMouseFunc(myMouse) ).
Can anyone help me with this?

[This message has been edited by tosomnic (edited 10-11-2002).]

[This message has been edited by tosomnic (edited 10-11-2002).]

tinak
10-12-2002, 01:30 AM
My first guess is that the program cannot locate the functions specified in the callback command.

If the function is in the code does it appear before the code uses it. Or have you pre-specified it at the top of the program ?

If you are not sure post the code up here or somewhere so that we can take a look and see what could be causing it.

Tina

tosomnic
10-12-2002, 04:34 AM
Yes, the functions are defined above...
Here's the code:

#include <GL\glut.h>
#include <math.h>
#include <iostream.h>

#define WINDOW_HEIGHT 200
#define WINDOW_WIDTH 200
#define WINDOW_X 100
#define WINDOW_Y 150

float A, B, C, D;

void myInit() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
}

void coordInit() {
glOrtho(0.0, 1.0, 1.0, 0.0, -1.0, 1.0);
}

void myMouse(int button, int state, int x, int y) {
if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) {
exit(0);
}
}

void myDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT);
}

void main(int argc, char **argv) {

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(WINDOW_HEIGHT, WINDOW_WIDTH);
glutInitWindowPosition(WINDOW_X, WINDOW_Y);

glutDisplayFunc(myDisplay);
glutMouseFunc(myMouse);

myInit();

coordInit();

glutMainLoop();

}

As you can see, the program really does nothing except for open a window and wait for the user to right click and then quits...

If I comment out both glutDisplayFunc(myDisplay) and glutMouseFunc(myMouse), it works fine (well, it doesn't really work because it complains about not having opened a window when it enters glutMainLoop), but when I add either one back in, it gives me the error http://www.opengl.org/discussion_boards/ubb/frown.gif

I'm not sure if this helps any, but when it gives me the error, the deebugger goes into disassembly mode and points to the line:
1000BBAE mov dword ptr [eax+0A8h],ecx


[This message has been edited by tosomnic (edited 10-12-2002).]

Bob
10-12-2002, 04:58 AM
...the program really does nothing except for open a window and wait...

No, the program does not create a window, because you don't call glutCreateWindow().

tinak
10-12-2002, 05:00 AM
EDIT: Ah, Bob beat me to it ... but heres the piece of code showing where to place it.. The window you see appear is the console window.

This is where the problem is :

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(WINDOW_HEIGHT, WINDOW_WIDTH);
glutInitWindowPosition(WINDOW_X, WINDOW_Y);

glutCreateWindow("Glut Test"); //creates a window

glutDisplayFunc(myDisplay);
glutMouseFunc(myMouse);

You need to create a window before setting up the function callbacks ;-)

Happy OpenGLing

Tina

[This message has been edited by tinak (edited 10-12-2002).]

tosomnic
10-12-2002, 06:37 AM
Hmmm... wow.... ummmmm... yeah....
Now I feel really silly http://www.opengl.org/discussion_boards/ubb/wink.gif
Well, thanks for the help... I really don't know how I missed that... I retyped the program 5 or 6 times, changing little things, but I never included that line...
hehehe...
Thanks again!
http://www.opengl.org/discussion_boards/ubb/smile.gif