小猿大D 2015-10-12 09:46 采纳率: 0%
浏览 3829

OPengl运行时窗口一闪而过,为毛啊?代码如下:

class GLintPoint
{
public:
GLint x,y;
};

class Point2
{
public :
float x,y;
void set(float dx, float dy)
{
x = dx;
y = dy;
}

void set(Point2 &p)
{
    x = p.x;
    y = p.y;
}

Point2(float xx, float yy)
{
    x = xx,
        y= yy;
}

Point2(){ x=y=0;}

};

Point2 currPos;
Point2 CP;

void moveTo(Point2 p)
{
CP.set(p);
}

void lineTo(Point2 p)
{
glBegin(GL_LINES);
glVertex2f(CP.x,CP.y);
glVertex2f(p.x,p.y);
glEnd();
glFlush( );
CP.set(p);
}

void myInit(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1.0, 0.0, 0.0, 0.0);
glColor3f(0.0, 0.0, 1.0);
}

void rosette(int N, float radius)
{
Point2 * pointlist = new Point2[N];
GLfloat theta = (2.0f * 3.1415926536)/N;
for(int c = 0; c<N; c++)
{
pointlist[c].set(radius * sin(theta * c),radius * cos(theta * c));
}

for(int i = 0; i<N; i++)
{
    for(int j = 0; j<N; j++)
    {
        moveTo(pointlist[i]);
        lineTo(pointlist[j]);
    }
}

}

void render()
{
glClear(GL_COLOR_BUFFER_BIT);
glViewport(10, 10, 640, 480);
rosette(5, 0.66f);
glFlush();
}

void main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glutInitWindowSize(640,480);
glutDisplayFunc(render);
myInit();
glutMainLoop();
}

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型