按照opengl超级宝典第五版上第一个三角形的程序清单打到配置好的vs2008上只有蓝色背景,没有红色三角形? 5
按照opengl超级宝典第五版上第一个三角形的程序清单打到配置已经配置好的好的visualstudio2008上,编译后本应该出现蓝色的背景和红色的三角形,为什么我的屏幕...
按照opengl超级宝典第五版上第一个三角形的程序清单打到配置已经配置好的好的visual studio 2008上,编译后本应该出现蓝色的背景和红色的三角形,为什么我的屏幕上只出现了蓝色背景,没有红色三角形?(编译后没有出现错误或是警告)
这是程序清单,跟书上一样:
#include<GLTools.h>
#include<GLShaderManager.h>
#include<windows.h>
#ifdef _APPLE_
#include<glut/glut.h>
#else
#define FREEGLUT_STATIC
#include<GL/glut.h>
#endif
GLBatch triangleBatch;
GLShaderManager shaderManager;
void ChangeSize(int w,int h)
{
glViewport(0,0,w,h);
}
void SetupRC()
{
glClearColor(0.0f,0.0f,1.0f,1.0f);
shaderManager.InitializeStockShaders();
GLfloat vVerts[]={-0.5f,0.0f,0.0f,
0.5f,0.0f,0.0f,
0.0f,0.0f,0.0f };
triangleBatch.Begin(GL_TRIANGLES,3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT |
GL_STENCIL_BUFFER_BIT);
GLfloat vRed[]={1.0f,0.0f,0.0f,1.0f};
shaderManager.UseStockShader
(GLT_SHADER_IDENTITY,vRed);
triangleBatch.Draw();
glutSwapBuffers();
}
int main(int argc,char* argv[])
{
gltSetWorkingDirectory(argv[0]);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA
| GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800,600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
GLenum err = glewInit();
if (GLEW_OK !=err){
fprintf(stderr,"GlEW Error:%s
\n",glewGetErrorString(err));
return 1;
}
SetupRC();
glutMainLoop();
return 0;
}
知识运行结果:
本人是初学者,望各位高手解释的清楚些。谢谢
! 展开
这是程序清单,跟书上一样:
#include<GLTools.h>
#include<GLShaderManager.h>
#include<windows.h>
#ifdef _APPLE_
#include<glut/glut.h>
#else
#define FREEGLUT_STATIC
#include<GL/glut.h>
#endif
GLBatch triangleBatch;
GLShaderManager shaderManager;
void ChangeSize(int w,int h)
{
glViewport(0,0,w,h);
}
void SetupRC()
{
glClearColor(0.0f,0.0f,1.0f,1.0f);
shaderManager.InitializeStockShaders();
GLfloat vVerts[]={-0.5f,0.0f,0.0f,
0.5f,0.0f,0.0f,
0.0f,0.0f,0.0f };
triangleBatch.Begin(GL_TRIANGLES,3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT |
GL_STENCIL_BUFFER_BIT);
GLfloat vRed[]={1.0f,0.0f,0.0f,1.0f};
shaderManager.UseStockShader
(GLT_SHADER_IDENTITY,vRed);
triangleBatch.Draw();
glutSwapBuffers();
}
int main(int argc,char* argv[])
{
gltSetWorkingDirectory(argv[0]);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA
| GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800,600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
GLenum err = glewInit();
if (GLEW_OK !=err){
fprintf(stderr,"GlEW Error:%s
\n",glewGetErrorString(err));
return 1;
}
SetupRC();
glutMainLoop();
return 0;
}
知识运行结果:
本人是初学者,望各位高手解释的清楚些。谢谢
! 展开
2个回答
展开全部
void SetupRC()
{
glClearColor(0.0f,0.0f,1.0f,1.0f);
shaderManager.InitializeStockShaders();
glTranslatef(0.0f,0.0f,-25.0f); //加上这一句话试试
GLfloat vVerts[]={-0.5f,0.0f,0.0f,
0.5f,0.0f,0.0f,
0.0f,0.0f,0.0f };
triangleBatch.Begin(GL_TRIANGLES,3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}
{
glClearColor(0.0f,0.0f,1.0f,1.0f);
shaderManager.InitializeStockShaders();
glTranslatef(0.0f,0.0f,-25.0f); //加上这一句话试试
GLfloat vVerts[]={-0.5f,0.0f,0.0f,
0.5f,0.0f,0.0f,
0.0f,0.0f,0.0f };
triangleBatch.Begin(GL_TRIANGLES,3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询