|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
GLUT Crashing
Hi all,
I've started to use the GLUT library, and have run across a problem. While my program compile fine, it crashes about five seconds after it begins running. I get an exception error 0xc0000005, and I don't know how to fix it. I looked up the error on Google, and it says that the exception indicates an attempt to access memory which is out of bounds, but in my program I don't see how that's relevant (unless there is an error in the GLUT library itself, which I don't know about). I'm running Dev-C++ 4.9.8.0 on Windows XP Home. The code I've used is below (it is just a copy of the code given from a tutorial at http://www.lighthouse3d.com): Code:
#include <gl/glut.h>
#include <gl/gl.h>
void RenderScene(void);
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("Testing GLUT");
glutDisplayFunc(RenderScene);
glutMainLoop();
return 0;
}
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,0.0);
glEnd();
glFlush();
}
Any help is greatly appreciated. Thank you in advance. Happy coding! ![]() |
|
#2
|
|||
|
|||
|
Can you run in debug mode to find where it's crashing - I don't see anything weird.
|
|
#3
|
|||
|
|||
|
I tried to run it in debug mode, but it immediately crashes when I begin. Therefore, I must assume the error is at glutMainLoop(), as I see a window that is rendered with the "scene" set by the RenderScene() function.
Perhaps my makefile may shed some light? Maybe I set the project up incorrectly? In any case, here's the makefile: Code:
# Project: GLUTest # Makefile created by Dev-C++ 4.9.8.0 CPP = g++.exe CC = gcc.exe WINDRES = windres.exe RES = OBJ = main.o $(RES) LINKOBJ = main.o $(RES) LIBS = -L"C:/DevCpp/lib" -lglut32 -lglu32 -lopengl32 ../../WINDOWS/system32/glut32.dll ../../WINDOWS/system32/glu32.dll ../../WINDOWS/system32/opengl32.dll INCS = -I"C:/DevCpp/include" -I"C:/DevCpp/include/SDL" CXXINCS = -I"C:/DevCpp/include/c++" -I"C:/DevCpp/include/c++/mingw32" -I"C:/DevCpp/include/c++/backward" -I"C:/DevCpp/include" -I"C:/DevCpp/include/SDL" BIN = glutest.exe CXXFLAGS = $(CXXINCS)-D_WCHAR_T_DEFINED -mwindows CFLAGS = $(INCS) -mwindows .PHONY: all all-before all-after clean clean-custom all: all-before glutest.exe all-after clean: clean-custom rm -f $(OBJ) $(BIN) $(BIN): $(LINKOBJ) $(CPP) $(LINKOBJ) -o "glutest.exe" $(LIBS) main.o: main.cpp $(CPP) -c main.cpp -o main.o $(CXXFLAGS) Thank you for attempting to help me. Happy coding! ![]() |
|
#4
|
||||
|
||||
|
Coincidentally I just started learning OpenGL just a few days ago. So I'm no expert, but I'll give it a shot
![]() First off, the code you posted works fine for me, in Linux. No crashes whatsoever. Maybe I'll try it on my Windows box later. The only thing I can spot is that glutInitDisplayMode()'s argument contains a GLUT_RGBA, whereas all my examples show only GLUT_RGB. Also, if that doesn't work, try calling it with -only- GLUT_RGB: Code:
glutInitDisplayMode(GLUT_RGB); That's all I can think of so far. A few side notes though: you don't have to include gl.h, since glut.h already does it for you. And if you ever want to port your code to UNIX or Linux, try using <GL/glut.h> instead of <gl/glut.h>; both UNIX and Linux are case-sensitive (I had to change that to be able to compile the code in Linux). Good luck!
__________________
"A poor programmer is he who blames his tools." http://analyser.oli.tudelft.nl/ |
|
#5
|
|||
|
|||
|
Well, I don't have to include gl.h for the main function(), but my entire RenderScene() function is built from OpenGL methods. Then again, I don't know a good deal about the functions provided by the GLUT library, so I may be able to take the GL functions and transpose them to GLUT functions.
Thanks for the tip about case-sensitive file systems in *nix, but what I'm doing right now is just or fun -- I don't plan on releasing anything, much less on *nix systems (as I don't have any to test on). I tried modifying from GLUT_RGBA to GLUT_RGB, but it still crashed with the same exception. I'm so lost. ![]() Thank you for the suggestion, though! I may just have to go back to WinMain/WndProc -- ugh. ![]() Happy coding! ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > GLUT Crashing |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|