【问题标题】:Error when running OpenGL project under Ubuntu 10.10在 Ubuntu 10.10 下运行 OpenGL 项目时出错
【发布时间】:2011-01-31 14:13:47
【问题描述】:

我有一个 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>

【问题讨论】:

  • 既然你得到了可执行文件,你的程序就被编译和链接了,它只是不能正常工作——标题具有误导性

标签: c++ opengl glut ubuntu-10.10


【解决方案1】:

你必须调用glutCreateWindow 之前你设置窗口的属性。您的代码,已修复(我已将宽度和高度常量替换为 300 只是为了让它编译并注释掉鼠标处理程序注册):

#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

#include <GL/glut.h>
#include <GL/glu.h>

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, 300, 300, 0,-1,1);

    glViewport (0,0,300, 300);
    //drawing ... 
}

int main(int argc, char* argv[])
{
    glutInit (&argc, argv);
    glutInitDisplayMode (GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH); // color, buffer
    glutCreateWindow ("Convex hull");
    glutInitWindowPosition (100, 100);
    glutInitWindowSize (300, 300);
    glutDisplayFunc (renderScene);
    //glutMouseFunc (mouse);
    glutMainLoop ();
}

【讨论】:

  • glutCreateWindow ("Hello, GLUT Window!"); glutInitWindowPosition (100, 100); glutInitWindowSize (300, 300); glutCreateWindow ("凸包");我正在创建窗口:)
  • 对,但是你必须在设置它的属性之前创建它......所以在那些 init 调用之后我什至没有注意到它:-)
  • 好的,它创建了窗口但不显示它。我单击窗口应位于的位置并在控制台中获取输出。很奇怪
  • 好的,一切都很好。当我从文件夹中运行它时,它会正确显示。感谢您的帮助,您为我指明了寻找的方向;)
  • @Vlad Lazarenko 我有同样的错误stackoverflow.com/questions/4914315/problem-with-glut 即使从文件夹中打开它
猜你喜欢
  • 2012-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多