# newbie opengl question

## Recommended Posts

Hi there. I’m trying to get back to doing some openGL programming but have come across a rather annoying and confusing problem After I compile a program I’ve written (Borland bcc32 if that’s important) and try to run the .exe, I get a ' test1.exe has encountered a problem and needs to close. We are sorry for the inconvenience' error with windows asking if I want to send an error report (to who… me?). I assumed it was my programming ineptitude so I tired opening a simple exe (just opens a blank window) and the same error pops up. I don’t know what to do. Any help you guys could give would be great. Cheers.

##### Share on other sites
Wow. That was quick

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

void init ( void ) {
glEnable ( GL_DEPTH_TEST );
glClearColor ( 0.0, 0.0, 0.0, 0.0 );
}

void display ( void ) {
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix ( );
glPopMatrix ( );
glutSwapBuffers ( );
}

void reshape(int w, int h) {
glViewport ( 0, 0, w, h );
glMatrixMode ( GL_PROJECTION );
if ( h==0 )
gluPerspective ( 80, ( float ) w, 1.0, 5000.0 );
else
gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
glMatrixMode ( GL_MODELVIEW );

}

void keyboard ( unsigned char key, int x, int y ) {
switch ( key ) {
case 27: /* Escape key */
exit ( 0 );
break;
case 'f':
glutFullScreen ( );
break;
case 'w':
glutReshapeWindow ( 250,250 );
break;
default:
break;
}
}

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

It's as simple a program as I could make. I even got a mate to compile and run it and he had no problems.

##### Share on other sites
Well, if your mate could compile and run it without problems, have you tried to do a clean and then build it from scratch? Probably under "Build" menu.

Also, I can't see any point to having these two lines called one after the other:
glPushMatrix ( );glPopMatrix ( );

##### Share on other sites
I'd also make sure that your OGL files are all of the same version. If so, make sure they are the latest.

##### Share on other sites
Cheers all. First off, the glPushMatrix() and glPopMatrix() were left behind from hacking my code down to see what was wrong with it, well spotted. I have tried cleaning and building from scratch repeatedly without much luck.

I've also changed to the latest glut32 files... nothin’.

##### Share on other sites
Wait a minute. I've just tired linking the compiled file and got loads of these error messages

Error: Unresolved external 'glutInit' referenced from C:\DOCUMENTS AND SETTINGS\MY DOCUMENTS\CPROJECTS\TESTER\TEST1.OBJ
Error: Unresolved external 'glutInitDisplayMode' referenced from C:\DOCUMENTS AND SETTINGS\MY DOCUMENTS\CPROJECTS\TESTER\TEST1.OBJ
***
***
***
Error: Unresolved external 'glutInitWindowSize' referenced from C:\DOCUMENTS AND SETTINGS\MY DOCUMENTS\CPROJECTS\TESTER\TEST1.OBJ
Error: Unresolved external 'glutCreateWindow' referenced from C:\DOCUMENTS AND SETTINGS\MY DOCUMENTS\CPROJECTS\TESTER\TEST1.OBJ

I think why this didn’t come up before was because my clean tool's settings were wrong. Sorry if this has wasted any of your time, but how do I sort this out?

##### Share on other sites
What do you mean changed to the latest glut32 files??

##### Share on other sites
You didn't link to the GLUT library?

##### Share on other sites
I’ve linked to glut.lib now, and it crates an exe. Which is nice. But now it gives me a new runtime error message:

test1.exe - Unable to Locate Component
This application has failed to start because OPENGL.dll was not found. Re-initialising the application may fix this problem.

Any ideas?

##### Share on other sites
Are you sure it's OPENGL.dll and not OpenGL32.dll?

##### Share on other sites
From OpenGL.org:

Quote:
 If you see files such as opengl.lib and glut.lib, these are SGI's unsupported libraries for Microsoft Windows. They should not be used. To use hardware acceleration, the Microsoft libraries are recommended. More info on the SGI libraries can be found here. Always link with either all Microsoft libraries (e.g., glu32.lib, glut32.lib, and opengl32.lib) or all SGI libraries (e.g., glu.lib, glut.lib, and opengl.lib). You can't use a combination of both Microsoft libarires and SGI libraries. However, you can install both sets of libraries on the same system. If you use SGI's .lib files, you'll need the corresponding .dll files installed in your system folder. (i.e., linking against opengl.lib requires that opengl.dll is installed at run time).

I think you should link against the Microsoft libraries glut32.lib and opengl32.lib. OpenGL.dll is SGI I think.

##### Share on other sites
Thanks for that Perfectly Dark. It sorted out the "OPENGL.dll was not found".

But now all I get is the error message from the original post:

test1.exe has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.
We have created an error report that you can send to us.
We will treat this report as confidential and anonymous.

##### Share on other sites
You should run your program in Debug, that way it will tell you where your program crashes and you should have more clue. Never used bloodshed, in VS.net you run the program with Start (not start without debugging) and you compile with the debug configuration.

##### Share on other sites
I’ve just been debugging it with Turbo Debugger (td32.exe), and the trace stops on an exception throw on line 50 [ glutCreateWindow ( argv[0] ); ]. I can’t see anything wrong with this line of code myself, but is it a clue?

Incidentally, I’m using Jens' File Editor, but that wouldn't make a difference, would it?

##### Share on other sites
hmm...I've never actually used GLUT sho this is a shot in the dark, but it seems that you're getting the argument for glutCreateWindow (which is the window name I believe) as an argument when your application is started. Are you remembering to execute with that argument? Perhaps try calling glutCreateWindow with a static string e.g. glutCreateWindow("test");

Just a guess...

##### Share on other sites
Nah, that didn't do it. I'm getting the same error message:

test1.exe has encountered a problem and needs to close etc.

##### Share on other sites
Ok, I copy/pasted the above code and I had to make a few changes but when it compiled it worked fine. Here's what I changed:

#include <windows.h>
#include <GL\gl.h>
#include <GL\glu.h>
#include <GL\glaux.h>
#include <glut.h>
#include <stdio.h>
#include <stdlib.h>

I needed to get GLUT for Win32 from here

Added library/include path to the unzipped GLUT folder (so it knows where to fine glut.h).

Moved glut32.dll into the debug folder in my project directory.

And Linked Libraries: glu32.lib glut32.lib opengl32.lib

Try doing that, if it fails that I don't think it's anything wrong with your code...

##### Share on other sites
I tried that eariler and now get the following compile time errors:

Error E2337 C:\Program Files\Borland\BCC55\Include\GL/glut.h 146: Only one of a set of overloaded functions can be "C"
Error E2015 test1.cpp 33: Ambiguity between 'std::exit(int)' and 'exit(int)' in function keyboard(unsigned char,int,int)

searching google, I found that fixing this meant using a different glut.h from the one you suggested (i dont know how or why, but it worked)

##### Share on other sites
So, does anyone know whats up with that error:

test1.exe has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.
We have created an error report that you can send to us.
We will treat this report as confidential and anonymous.

##### Share on other sites
hehehe. Just sorted it out. I feel like such an idiot. In case anyone wanted to know, i put opengl32.dll in c:\windows\system, but it should have been in c:\windows\system