初学者关于OpenGL的如何编出一个正方形的问题。下面的这段程序有什么问题?为什么显示的是白屏?
#include"stdafx.h"#include<GL/glut.h>voidinit(void){glClearColor(0,0,0,0);}voidreshap...
#include "stdafx.h"
#include <GL/glut.h>
void init(void)
{
glClearColor(0,0,0,0);
}
void reshape(int w,int h )
{
glViewport(0,0,10,10);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
void myDisplay()
{
glColor3f(1.0,1.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex3f(0.0,0.0,0.0);
glVertex3f(-1.0,0.0,0.0);
glVertex3f(1.0,-1.0,0.0);
glVertex3f(0.0,-1.0,0.0);
glEnd;
glFlush;
}
int _tmain(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutInitWindowPosition(0, 0);
glutInitWindowSize(400, 400);
glutCreateWindow("第一个OpenGL程序");
glutDisplayFunc(myDisplay);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
} 展开
#include <GL/glut.h>
void init(void)
{
glClearColor(0,0,0,0);
}
void reshape(int w,int h )
{
glViewport(0,0,10,10);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
void myDisplay()
{
glColor3f(1.0,1.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex3f(0.0,0.0,0.0);
glVertex3f(-1.0,0.0,0.0);
glVertex3f(1.0,-1.0,0.0);
glVertex3f(0.0,-1.0,0.0);
glEnd;
glFlush;
}
int _tmain(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutInitWindowPosition(0, 0);
glutInitWindowSize(400, 400);
glutCreateWindow("第一个OpenGL程序");
glutDisplayFunc(myDisplay);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
} 展开
4个回答
展开全部
1、你犯了和这个问题一样的错误,reshape函数里关于投影和模型矩阵的设置全部错误:
http://zhidao.baidu.com/question/1382135500701951620.html?oldq=1
2、display函数里最后不要用glFlush,用 glutSwapBuffers();,否则画再多也看不到。(还有那个glEnd是不是少个括号?)
http://zhidao.baidu.com/question/1382135500701951620.html?oldq=1
2、display函数里最后不要用glFlush,用 glutSwapBuffers();,否则画再多也看不到。(还有那个glEnd是不是少个括号?)
--
2022-12-05 广告
2022-12-05 广告
图形化编程简单理解为用积木块形式编程,scratch和python也是其中的一种,属于入门级编程,以其简单生动的画面获得无数学生的喜爱,深圳市创客火科技有限公司是一家做教育无人机的公司,旗下有编程无人机,积木无人机及室内外编队,每款飞机含有...
点击进入详情页
本回答由--提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询