Ubuntu 10.10下运行OpenGL项目出错

发布于 2024-10-15 06:13:54 字数 1295 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我爱人 2024-10-22 06:13:54

在设置窗口的属性之前,您必须调用 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 ();
}

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):

#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 ();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文