首页 新闻 会员 周边 捐助

opengl只显示窗口不显示窗口内容?

0
悬赏园豆:5 [已解决问题] 解决于 2012-09-11 19:00

写了个dome,执行结果只显示窗口,但是窗口内什么都没有,有没有哪位知道这是为什么?

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

#define GLfloat float

void myinit()
{
glClearColor(0.0, 0.5, 0.5, 1.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,50.0,0.0,50.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(25.0, 0.0, 50.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

}


void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
GLfloat vertices[3][2]={{0.0, 0.0 }, {25.0, 50.0 }, {50.0, 0.0 }};
GLfloat p[2]={7.50, 5.0 };

int j,k;
glBegin(GL_POINTS);
for(k=0;k<500;k++)
{
j=k%3;
p[0]=(p[0]+vertices[j][0])/2;
p[1]=(p[1]+vertices[j][1])/2;
glVertex2fv(p);
}
glEnd();
glFlush();
}

 

void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("实验一");

myinit();
glutDisplayFunc(display);

glutMainLoop(); 

}

知足linear的主页 知足linear | 初学一级 | 园豆:199
提问于:2012-09-11 16:12
< >
分享
最佳答案
0

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


//#define GLfloat float

void myinit()
{
glClearColor(1.0, 1.0, 1.0, 1.0);

glColor3f(1.0, 0.0, 0.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,50.0,0.0,50.0);
glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
//gluLookAt(25.0, 0.0, 50.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

}


void display()
{
// glColor3f(0.0, 0.0, 1.0);
GLfloat vertices[3][2]={{0.0, 0.0 }, {25.0, 50.0 }, {50.0, 0.0 }};

int i,j,k;
//int rand();
GLfloat p[2]={7.50, 5.0 };


glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
// glVertex2fv(p);
// glColor3f(0.0,1.0,0.0);
for(k=0;k<5000;k++)
{
j=rand()%3;
// j=k%3;
p[0]=(p[0]+vertices[j][0])/2.0;
p[1]=(p[1]+vertices[j][1])/2.0;
// p[2]=(p[2]+vertices[j][2])/2;
glVertex2fv(p);
}
glEnd();
glFlush();
}

 

void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("实验一");

glutDisplayFunc(display);

myinit();

glutMainLoop(); //进入事件循环

}

知足linear | 初学一级 |园豆:199 | 2012-09-11 17:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册