首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Edward示例OpenGL代码:在联想X60上运行良好,但在我的桌面上不呈现窗口()

Edward示例OpenGL代码:在联想X60上运行良好,但在我的桌面上不呈现窗口()
EN

Stack Overflow用户
提问于 2013-08-20 08:45:03
回答 1查看 832关注 0票数 1

我是OpenGL的新手,并试图从Edward的著名著作中运行一些经典的示例代码。然而,我遇到了一个困扰我的问题,但可能对其他许多人来说是非常明显的。示例代码是"Gasket.c“,可以从EDITION/PROGRAMS/CHAPTER02/下载

我使用VS2010 Express在我的联想X60 (windows 7)上运行了这段代码,它成功地绘制了Sierspinski垫圈。然而,它没有画任何东西,只显示一个空白(白色)窗口时,我试图运行相同的代码在我的桌面(英特尔高清图形卡)与相同的软件系统。该文件是在没有问题的情况下编写/生成的,没有错误/警告。

如下所示:

代码语言:javascript
复制
/* Two-Dimensional Sierpinski Gasket          */
/* Generated Using Randomly Selected Vertices */
/* And Bisection                              */

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

void myinit()
{

/* attributes */

     glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */
     glColor3f(1.0, 0.0, 0.0); /* draw in red */

/* set up viewing */
/* 500 x 500 window with origin lower left */

     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     gluOrtho2D(0.0, 50.0, 0.0, 50.0);
     glMatrixMode(GL_MODELVIEW);
}

void display( void )
{
    GLfloat vertices[3][2]={{0.0,0.0},{25.0,50.0},{50.0,0.0}}; /* A triangle */

    int j, k;
    int rand();       /* standard random number generator */
    GLfloat p[2] ={7.5,5.0};  /* An arbitrary initial point inside traingle */

    glClear(GL_COLOR_BUFFER_BIT);  /*clear the window */


/* compute and plots 5000 new points */

        glBegin(GL_POINTS);

    for( k=0; k<5000; k++)
    {
         j=rand()%3; /* pick a vertex at random */


     /* Compute point halfway between selected vertex and old point */

         p[0] = (p[0]+vertices[j][0])/2.0; 
         p[1] = (p[1]+vertices[j][1])/2.0;

     /* plot new point */

        glVertex2fv(p); 

     }
     glEnd();
     glFlush(); /* clear buffers */
   }

void main(int argc, char** argv)
{

/* Standard GLUT initialization */

    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */
    glutInitWindowSize(500,500); /* 500 x 500 pixel window */
    glutInitWindowPosition(0,0); /* place window top left on display */
    glutCreateWindow("Sierpinski Gasket"); /* window title */
    glutDisplayFunc(display); /* display callback invoked when window opened */

    myinit(); /* set attributes */

    glutMainLoop(); /* enter event loop */
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-20 14:40:27

尝试从单缓冲(GLUT_SINGLE)切换到双缓冲(GLUT_DOUBLE):

代码语言:javascript
复制
#include <GL/glut.h>

void display( void )
{
    GLfloat vertices[3][2]={{0.0,0.0},{25.0,50.0},{50.0,0.0}}; /* A triangle */

    int j, k;
    int rand();       /* standard random number generator */
    GLfloat p[2] ={7.5,5.0};  /* An arbitrary initial point inside traingle */

    glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */
    glClear(GL_COLOR_BUFFER_BIT);  /*clear the window */

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluOrtho2D(0.0, 50.0, 0.0, 50.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    /* compute and plots 5000 new points */
    glColor3f(1.0, 0.0, 0.0); /* draw in red */
    glBegin(GL_POINTS);
    for( k=0; k<5000; k++)
    {
        j=rand()%3; /* pick a vertex at random */

        /* Compute point halfway between selected vertex and old point */
        p[0] = (p[0]+vertices[j][0])/2.0; 
        p[1] = (p[1]+vertices[j][1])/2.0;

        /* plot new point */
        glVertex2fv(p); 

    }
    glEnd();

    glutSwapBuffers();
}

void main(int argc, char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); /* default, not needed */
    glutInitWindowSize(500,500); /* 500 x 500 pixel window */
    glutInitWindowPosition(0,0); /* place window top left on display */
    glutCreateWindow("Sierpinski Gasket"); /* window title */
    glutDisplayFunc(display); /* display callback invoked when window opened */
    glutMainLoop(); /* enter event loop */
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18330694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档