PDA

View Full Version : How to solve problem "0xC0000005 Access Violation"



onethreeninetwo
01-12-2014, 09:43 PM
Hi everyone, I'm a newbie of OpenGL.
I'm testing a very simple code from "the OpenGL Red Book", but get this error "0xC0000005 Access Violation".
My environment is : Win 7 32bit, Visual Studio 2010
The code is as followed:



#include <glut.h>

void init(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,200.0,0.0,150.0);
}

void lineSegment(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINES);
glVertex2i(100,0);
glVertex2i(0,75);
glEnd();
glFlush();
}

int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(400,300);
glutCreateWindow("test");

init();
glutDisplayFunc(lineSegment);
glutMainLoop();

return 0;
}


I'd be very grateful if you can give any piece of advise. Thanks in advance!

chbaker0
01-14-2014, 05:11 PM
Try running it with debugging, so you can get more information on where the error is occurring.

Jesse
01-15-2014, 11:25 AM
Hi everyone, I'm a newbie of OpenGL.
I'm testing a very simple code from "the OpenGL Red Book", ...

You're not using the current 8th edition Red Book source code. For the latest code, download the Red Book examples from this website: http://www.opengl-redbook.com/