Question

I made a new project and pretty much copied this guide, but whenever I call any OpenGL function it the spot marked // Drawing code here it crashes. I have this there :

glViewport(0, 0, [self bounds].size.width, [self bounds].size.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, [self bounds].size.width, [self bounds].size.height, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.375, 0.375, 0.0);

glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0, 0, 0);

glBegin(GL_LINES);
glVertex2f(10, 10);
glVertex2f(300, 300);
glEnd();

glFlush();

But just calling one OpenGL function crashes it, reporting GDB: Program received signal: "EXC_BAD_ACCESS". First of all, if it did work, is that code good? Doing all that stuff at the top every time it gets called? Its supposed to be for 2d, with origin at top-left. And why is it crashing? I have CoreVideo and OpenGL linked and imported... I want to get a Cocoa application set up to use OpenGL so I can focus on the game code.

Thanks.

Was it helpful?

Solution

The article you linked isn't really a complete project -- it's just a discussion and sample of using CVDisplayLink to drive the drawing loop. You'll probably do better by starting with Apple's OpenGL Programming Guide.

OTHER TIPS

Check out MyOpenGLView.m in Apple's sample code for GLFullScreen. They use CVDisplayLink successfully. The thing missing in "Driving OpenGL Rendering Loops" is the fact that you need to add a mutex to avoid two threads accessing the same opengl context.

You could try replacing '[self bounds].size.width' with hard-coded numbers to see if that is part of the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top