请问openGL画图无法显示是怎么回事呢? 200
我采用glm库来载入了3dmax导出的obj模型,经过检测,读入是正确的,然后我绘制它,奇怪的是总是看不见模型,我试着绘制了一个三角形,却可以显示。求大神帮助~#incl...
我采用glm库来载入了3dmax导出的obj模型,经过检测,读入是正确的,然后我绘制它,奇怪的是总是看不见模型,我试着绘制了一个三角形,却可以显示。求大神帮助~
#include "glm.h"
#include<gl/glut.h>
#include<gl/GLU.h>
#include<stdio.h>
void background(void)
{
glClearColor(0.0,0.0,0.0,0.0);//设置背景颜色为黑色
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);//buffer设置为颜色可写
glClearColor(0.0f,0.0f,0.0f,0.0f);
//glBegin(GL_TRIANGLES);//开始画三角形
//glShadeModel(GL_SMOOTH);//设置为光滑明暗模式
// glColor3f(1.0,0.0,0.0);//设置第一个顶点为红色
//glVertex2f(-1.0,-1.0);//设置第一个顶点的坐标为(-1.0,-1.0)
//glColor3f(0.0,1.0,0.0);//设置第二个顶点为绿色
//glVertex2f(0.0,-1.0);//设置第二个顶点的坐标为(0.0,-1.0)
//glColor3f(0.0,0.0,1.0);//设置第三个顶点为蓝色
//glVertex2f(-0.5,1.0);//设置第三个顶点的坐标为(-0.5,1.0)
//glEnd();//三角形结束
//glLoadIdentity();
GLMmodel* model;
model=glmReadOBJ("foot6.obj");
glmDraw(model,GLM_SMOOTH);
glFlush();//强制OpenGL函数在有限时间内运行
glutSwapBuffers();
}
void myReshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);//设置视口
glMatrixMode(GL_PROJECTION);//指明当前矩阵为GL_PROJECTION
glLoadIdentity();//将当前矩阵置换为单位阵
if(w <= h)
gluOrtho2D(-1.0,1.5,-1.5,1.5*(GLfloat)h/(GLfloat)w);//定义二维正视投影矩阵
else
gluOrtho2D(-1.0,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5);
glMatrixMode(GL_MODELVIEW);//指明当前矩阵为GL_MODELVIEW
}
int main(int argc,char ** argv)
{
/*初始化*/
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(400,400);
glutInitWindowPosition(200,200);
/*创建窗口*/
glutCreateWindow("Triangle");
/*绘制与显示*/
background();
//GLfloat lightPos[] = {0.0f,0.0f,10.0f};
//GLfloat ambientLight[]={1.0f,1.0f,1.0f,0.0f};//白色主光源环境光
//GLfloat diffuseLight[]={1.0f,1.0f,1.0f,0.0f};//白色主光源漫反射
//GLfloat specularLight[]={1.0f,1.0f,1.0f,1.0f};//白色主光源镜面光
//glEnable(GL_LIGHTING); //启用光照
//glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight); //设置环境光源
//glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight); //设置漫反射光源
//glLightfv(GL_LIGHT0,GL_SPECULAR,specularLight); //设置镜面光源
//glLightfv(GL_LIGHT0,GL_POSITION,lightPos); //设置灯光位置
//glEnable(GL_LIGHT0); //打开白色主光源
glutReshapeFunc(myReshape);
glutDisplayFunc(myDisplay);
glutMainLoop();
return(0);
} 展开
#include "glm.h"
#include<gl/glut.h>
#include<gl/GLU.h>
#include<stdio.h>
void background(void)
{
glClearColor(0.0,0.0,0.0,0.0);//设置背景颜色为黑色
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);//buffer设置为颜色可写
glClearColor(0.0f,0.0f,0.0f,0.0f);
//glBegin(GL_TRIANGLES);//开始画三角形
//glShadeModel(GL_SMOOTH);//设置为光滑明暗模式
// glColor3f(1.0,0.0,0.0);//设置第一个顶点为红色
//glVertex2f(-1.0,-1.0);//设置第一个顶点的坐标为(-1.0,-1.0)
//glColor3f(0.0,1.0,0.0);//设置第二个顶点为绿色
//glVertex2f(0.0,-1.0);//设置第二个顶点的坐标为(0.0,-1.0)
//glColor3f(0.0,0.0,1.0);//设置第三个顶点为蓝色
//glVertex2f(-0.5,1.0);//设置第三个顶点的坐标为(-0.5,1.0)
//glEnd();//三角形结束
//glLoadIdentity();
GLMmodel* model;
model=glmReadOBJ("foot6.obj");
glmDraw(model,GLM_SMOOTH);
glFlush();//强制OpenGL函数在有限时间内运行
glutSwapBuffers();
}
void myReshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);//设置视口
glMatrixMode(GL_PROJECTION);//指明当前矩阵为GL_PROJECTION
glLoadIdentity();//将当前矩阵置换为单位阵
if(w <= h)
gluOrtho2D(-1.0,1.5,-1.5,1.5*(GLfloat)h/(GLfloat)w);//定义二维正视投影矩阵
else
gluOrtho2D(-1.0,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5);
glMatrixMode(GL_MODELVIEW);//指明当前矩阵为GL_MODELVIEW
}
int main(int argc,char ** argv)
{
/*初始化*/
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(400,400);
glutInitWindowPosition(200,200);
/*创建窗口*/
glutCreateWindow("Triangle");
/*绘制与显示*/
background();
//GLfloat lightPos[] = {0.0f,0.0f,10.0f};
//GLfloat ambientLight[]={1.0f,1.0f,1.0f,0.0f};//白色主光源环境光
//GLfloat diffuseLight[]={1.0f,1.0f,1.0f,0.0f};//白色主光源漫反射
//GLfloat specularLight[]={1.0f,1.0f,1.0f,1.0f};//白色主光源镜面光
//glEnable(GL_LIGHTING); //启用光照
//glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight); //设置环境光源
//glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight); //设置漫反射光源
//glLightfv(GL_LIGHT0,GL_SPECULAR,specularLight); //设置镜面光源
//glLightfv(GL_LIGHT0,GL_POSITION,lightPos); //设置灯光位置
//glEnable(GL_LIGHT0); //打开白色主光源
glutReshapeFunc(myReshape);
glutDisplayFunc(myDisplay);
glutMainLoop();
return(0);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询