我正在开发OpenGL和Xcode4的第一步。 因此我创建了一个新的项目(应用程序 - >命令行工具 - > C++)。Xcode4和OpenGL - 编程接收信号:EXC_BAD_ACCESS
在项目我去目标 - >构建阶段 - >链接二进制与图书馆并添加两个框架:OpenGL.framework和GLUT.framework
这是我的main.cpp:
#include <iostream>
#include <stdlib.h>
#include <GLUT/glut.h>
void RenderScene()
{
glLoadIdentity();
glBegin(GL_POLYGON);
glColor4f(1.0, 0.0, 0.0, 1.0);
glVertex3f(-0.5, -0.5, -0.5);
glVertex3f( 0.5, -0.5, -0.5);
glVertex3f( 0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, -0.5);
glEnd();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutCreateWindow("Name_1; Name_2");
glutDisplayFunc(RenderScene);
return 0;
}
当我运行项目时,构建成功。
,但在行glutCreateWindow("Name_1; Name_2");
的Xcode告诉我“主题1:程序接收到的信号: “EXC_BAD_ACCESS”,并没有出现任何的窗口
请帮我:)谢谢
[!编辑]
这里是堆栈跟踪:
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
[Switching to process 7126 thread 0x0]
2011-03-30 16:14:45.052 OpenGL[7126:903] NSSoftLinking - The function 'CGLSetOption' can't be found in the OpenGL framework.
sharedlibrary apply-load-rules all
Current language: auto; currently c++
(gdb) where
#0 0x0000000000000000 in ??()
#1 0x00007fff815efb43 in createPixelFormat()
#2 0x00007fff815efae9 in -[NSOpenGLPixelFormat initWithAttributes:]()
#3 0x000000010001bad3 in createPixelFormat()
#4 0x000000010001b251 in __glutDeterminePixelFormat()
#5 0x000000010001b3f7 in __glutCreateWindow()
#6 0x000000010001b7bd in glutCreateWindow()
#7 0x0000000100000d2b in main (argc=1, argv=0x7fff5fbff6e8) at /Users/.../main.cpp:23
Current language: auto; currently c++
(gdb)
请出示从gdb的堆栈跟踪。 – trojanfoe 2011-03-30 13:54:07
顺便说一下:我添加了'glutMainLoop()'到最后,并在Linux下尝试了它,它工作得很好(使用freeglut),所以它基本上可以。 – trojanfoe 2011-03-30 14:03:02
对不起,我在哪里可以找到gdb的stacktrace? – Christoph 2011-03-30 14:09:25