在OS X中的Eclipse中的OpenGL和GLUT [英] OpenGL and GLUT in Eclipse on OS X
问题描述
我一直在试图在Eclipse中使用CDT设置OpenGL和GLUT库,但在OS X上并没有太大的成功。我似乎不能得到eclipse实际上实现GLUT是什么。它目前给我的错误,我有一个未解决的包含GL / glut.h。在网上查找我发现我应该使用-framework GLUT标志在gcc链接器设置,但这似乎无效。
I have been trying to setup the OpenGL and GLUT libraries in Eclipse, with CDT, on OS X with not very much success. I cannot seem to get eclipse to actually realize where GLUT is. It is currently giving me the error that I have an unresolved inclusion GL/glut.h. Looking around online I found that I should be using the -framework GLUT flag in the gcc linker settings, but this seems ineffective.
推荐答案
好的。我得到它工作在X11。我只能得到它的工作在X11的原因是因为看起来OpenGL libs在操作系统是64位架构,但eclipse只会编译代码,如果我们使用32位架构。也许如果这是固定的,我们可以使用OS X预安装的库。另外,也许有一个32位版本躺在操作系统上,我们可以使用,但我似乎找不到它。但是,我满足于使用X11作为我的学习目的。
Ok. I got it working in X11. The reason I could only get it working on X11 is because it seems the OpenGL libs on the OS are for the 64-bit architecture, but eclipse will only compile code if we use 32-bit architecture. Maybe if this got fixed we could use OS X pre-installed libraries. Also, maybe there is a 32-bit version lying around on the OS we could use that but I can't seem to find it. I, however, am content with using X11 for my learning purposes.
首先创建你的C ++项目。因为你不能使用eclipse编译64位的代码添加以下...
First create your C++ project. Then since you can't compile code in 64-bit using eclipse add the following...
然后你需要你的库和链接设置。为此,请执行以下操作:
Then you need your libraries and linking set up. To do this do the following:
最后,您需要设置DISPLAY变量。
Lastly you need to set a DISPLAY variable.
在尝试运行启动X11之前。
Before you try running start up X11.
尝试下面的代码来获得我在我的机器上运行的东西。希望它为你工作!
Try the following code to get something I've got running in my machine. Hope it works for you!
//#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();
}
这篇关于在OS X中的Eclipse中的OpenGL和GLUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!