fas*_*k20 8 c++ opengl macos glut eclipse-cdt
我一直试图在OS X上使用CDT在Eclipse中设置OpenGL和GLUT库并没有取得多大成功.我似乎无法让eclipse真正意识到GLUT在哪里.它目前给我一个错误,我有一个未解决的包含GL/glut.h.在网上查看我发现我应该在gcc链接器设置中使用-framework GLUT标志,但这似乎无效.
好.我在X11工作了.我之所以能够在X11上工作的原因是因为OS上的OpenGL库似乎是针对64位架构的,但是如果我们使用32位架构,eclipse只会编译代码.也许如果这个问题得到解决,我们可以使用OS X预装的库.此外,也许在我们可以使用的操作系统上有一个32位版本,但我似乎无法找到它.但是,我满足于将X11用于学习目的.
首先创建您的C++项目.那么既然你无法使用eclipse编译64位代码,请添加以下内容...
替代文字http://img132.imageshack.us/img132/5163/step1c32bit.png
替代文字http://img251.imageshack.us/img251/5163/step1c32bit.png
alt text http://img132.imageshack.us/img132/2325/step1linker32bit.png
然后你需要你的库和链接设置.为此,请执行以下操作:
替代文字http://img29.imageshack.us/img29/1904/step2linkerglglu.png
替代文字http://img196.imageshack.us/img196/4313/step2glut.png
最后,您需要设置一个DISPLAY变量.
alt text http://img40.imageshack.us/img40/7306/step3display.png
在您尝试运行启动X11之前.
尝试使用以下代码来获取我在机器中运行的内容.希望这对你有用!
//#include <GL/gl.h>
//#include <GL/glu.h>
#include <GL/glut.h>
#define window_width 640
#define window_height 480
// Main loop
void main_loop_function() {
// Z angle
static float angle;
// Clear color (screen)
// And depth (used internally to block obstructed objects)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Load identity matrix
glLoadIdentity();
// Multiply in translation matrix
glTranslatef(0, 0, -10);
// Multiply in rotation matrix
glRotatef(angle, 0, 0, 1);
// Render colored quad
glBegin( GL_QUADS);
glColor3ub(255, 000, 000);
glVertex2f(-1, 1);
glColor3ub(000, 255, 000);
glVertex2f(1, 1);
glColor3ub(000, 000, 255);
glVertex2f(1, -1);
glColor3ub(255, 255, 000);
glVertex2f(-1, -1);
glEnd();
// Swap buffers (color buffers, makes previous render visible)
glutSwapBuffers();
// Increase angle to rotate
angle += 0.25;
}
// Initialze OpenGL perspective matrix
void GL_Setup(int width, int height) {
glViewport(0, 0, width, height);
glMatrixMode( GL_PROJECTION);
glEnable( GL_DEPTH_TEST);
gluPerspective(45, (float) width / height, .1, 100);
glMatrixMode( GL_MODELVIEW);
}
// Initialize GLUT and start main loop
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitWindowSize(window_width, window_height);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("GLUT Example!!!");
glutDisplayFunc(main_loop_function);
glutIdleFunc(main_loop_function);
GL_Setup(window_width, window_height);
glutMainLoop();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15775 次 |
| 最近记录: |