【问题标题】:OpenGl problem with Ubuntu 10.10Ubuntu 10.10 的 OpenGL 问题
【发布时间】:2011-02-12 18:34:25
【问题描述】:

当我尝试运行此程序时,它会启动,显示标题栏但什么都没有 - 它只停靠在底部任务行,当我单击它时 - 没有任何显示。该程序没有窗口。任何想法 ?这是使用 OpenGL 的代码:

#include <GL/glut.h> // Header File For The GLUT Library 
#include <GL/gl.h> // Header File For The OpenGL32 Library 
#include <GL/glu.h> // Header File For The GLu32 Library

void SetupRC(void);
void RenderScene(void);
void ChangeSize(GLsizei w, GLsizei h);

// Called to draw scene
void RenderScene(void)
{
    // Clear the window with current clearing color
glClearColor (0.f,0.f,0.f,0.f);
glClear(GL_COLOR_BUFFER_BIT);

// set the color to these values
//          R    G     B
glColor3f(1.0f, 1.0f, 1.0f);

// Draw a filled rectangle with current color
glRectf(-25.0f, 25.0f, 25.0f, -25.0f);

// Flush drawing commands
glFlush();
glutSwapBuffers();
}

int main(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH); // color, buffer
    glutCreateWindow("Simple");
    glutInitWindowPosition(400,200);
    glutInitWindowSize(640,468);
    glutDisplayFunc(RenderScene);
    glutReshapeFunc(ChangeSize);

    SetupRC();
    glutMainLoop();

    return 0;
}

// Setup the rendering state
void SetupRC(void)
{
    glClearColor(0.0f, 1.0f, 1.0f, 0.0f);
}

// Handling window resizing
void ChangeSize(GLsizei w, GLsizei h)
{
    GLfloat aspectRatio;

    // Prevent divide by zero
    if (h == 0) 
        h = 1;

    // Set Viewport to window dimensions
    glViewport(0, 0, w, h);

    // Reset coordinate system
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    // Establish clipping volume (left, right, bottom, top, near, far)
    aspectRatio = (GLfloat) w / (GLfloat) h;
    if (w <= h) {
        glOrtho(-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0);
    }
    else
        glOrtho(-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0, 1.0, -1.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

【问题讨论】:

  • freeglut 是否将任何错误消息记录到应用程序的控制台?
  • 您是否启用了compiz?我已经编译了你的代码,并且可以确认它在 Ubuntu 10.10 上运行。
  • 或许可以尝试禁用它,看看问题是否仍然存在。
  • @eddflrs 当我禁用它时,窗口会显示其背后的内容
  • 可能是显卡相关问题。您是否使用了合适的驱动程序?我知道 OpenGL 在使用 ATI/Intel 卡时遇到了问题。顺便说一句,我读过一篇主题是罪魁祸首的帖子。

标签: opengl glut ubuntu-10.10 graphics freeglut


【解决方案1】:

从终端运行 glxinfo 并查看是否出现任何问题。 您可能需要安装 mesa-utils 才能使用 glxinfo

sudo apt-get install mesa-utils

从您分享的内容来看,这似乎是显卡问题。您也许可以在 Ubuntu 论坛上获得更好的帮助。祝你好运。

【讨论】:

    【解决方案2】:

    只需将单缓冲更改为双缓冲,它就会起作用(而不是 GLUT_SINGLE 放入 GLUT_DOUBLE)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      • 2015-02-08
      相关资源
      最近更新 更多