Ubuntu 10.10下运行OpenGL项目出错
我有一个 OpenGL 项目,用于查找用 Windows 编写的凸包。
现在我正在使用 Ubuntu 10.10,我尝试移植代码(它是 C++ 代码)并运行它。
我看到,它应该这样编译:
g++ convex.cpp -lm -lglut -lGLU -o convex_hull_project
它编译文件,但是当我运行文件 ./convex_hull_project
时,它启动程序,显示标题,但什么也没有 - 它只停靠在底部任务行,当我单击它时 - 什么也没有显示。 该程序没有窗口。 有什么想法吗? 这是使用 OpenGL 内容的代码:
int main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH); // color, buffer
glutInitWindowPosition(100,100);
glutInitWindowSize(window_size_width,window_size_height);
glutCreateWindow("Convex hull");
glutDisplayFunc(renderScene);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}
void renderScene(void) {
// clear framebuffer
glClearColor(0.f,0.f,0.f,0.f);
glClear(GL_COLOR_BUFFER_BIT);
// set-up matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,window_size_width,window_size_height,0,-1,1);
glViewport(0,0,window_size_width,window_size_height);
//drawing ...
}
包括:
#include<GL/glut.h>
#include<GL/glu.h>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
I had OpenGL project for finding a convex hull written in Windows.
Now i'm using Ubuntu 10.10 and i tried to port the code (It's C++ code) and run it.
I saw that, it should be compiled this way :
g++ convex.cpp -lm -lglut -lGLU -o convex_hull_project
It compiles the file, but when i run the file ./convex_hull_project
it starts the program, shows the title but there is nothing - it only docks for the bottom task line and when i click it - nothing shows. There is no window with the program.
Any idea ?
Here's the code that uses OpenGL stuff :
int main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH); // color, buffer
glutInitWindowPosition(100,100);
glutInitWindowSize(window_size_width,window_size_height);
glutCreateWindow("Convex hull");
glutDisplayFunc(renderScene);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}
void renderScene(void) {
// clear framebuffer
glClearColor(0.f,0.f,0.f,0.f);
glClear(GL_COLOR_BUFFER_BIT);
// set-up matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,window_size_width,window_size_height,0,-1,1);
glViewport(0,0,window_size_width,window_size_height);
//drawing ...
}
And includes are :
#include<GL/glut.h>
#include<GL/glu.h>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在设置窗口的属性之前,您必须调用 glutCreateWindow。您的代码已修复(我已将宽度和高度常量替换为 300,只是为了让它编译并注释掉鼠标处理程序注册):
You have to call
glutCreateWindow
before you set windows's properties. Your code, fixed (I've replaced width and height constants with 300 just to get it to compile and commented out mouse handler registration):