
用vc6.0编译opengl 这段代码,是通过控制点显示Bezier曲线,运行无问题,但是没有任何显示。请看看什么问题
//#include<windows.h>#defineGLUT_DISABLE_ATEXIT_HACK#include"gl/glut.h"voidInitializa...
//#include <windows.h>
#define GLUT_DISABLE_ATEXIT_HACK
#include "gl/glut.h"
void Initialization();
void OnDisplay();
void OnReshape(int,int);
void SetupLights();
void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(640,480);
glutInitWindowPosition(300,150);
glutCreateWindow("EXAMqumian");
glutDisplayFunc(OnDisplay);
glutReshapeFunc(OnReshape);
Initialization();
glutMainLoop();
}
void Initialization()
{
glClearColor(1.0f,1.0f,1.0f,1.0f);
glEnable(GL_MAP1_VERTEX_3);
}
void OnDisplay()
{
GLfloat aCtrlPts[][3]={{-300,100,0.0},{-50,210,0.0},{-100,100,0.0},{50,150,0.0},{70,10,0.0},{-200,-100,0.0},{20,-230,0.0},{250,30,0.0},{300,-200,0.0}};
GLint n=9,i;
glClear(GL_COLOR_BUFFER_BIT);
glMap1f(GL_MAP1_VERTEX_3,0.0f,1.0f,3,n,*aCtrlPts);
glColor3f(1.0f,0.0f,0.0f);
glLineWidth(3);
glBegin(GL_LINE_STRIP);
for(i=0;i<=50;i++)
glEvalCoord1f(GLfloat(i/50.0));
glEnd();
glFlush();
//glutSwapBuffers();
}
void OnReshape(int w,int h)
{
GLfloat aspect;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);//当前矩阵为投影模式
glLoadIdentity();
if (w<=h)
{
aspect=h/w;
gluOrtho2D(-w/2,w/2,-h*aspect/2,h*aspect/2);
}
else
{
aspect=w/h;
gluOrtho2D(-w*aspect/2,w*aspect/2,-h/2,h/2);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
} 展开
#define GLUT_DISABLE_ATEXIT_HACK
#include "gl/glut.h"
void Initialization();
void OnDisplay();
void OnReshape(int,int);
void SetupLights();
void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(640,480);
glutInitWindowPosition(300,150);
glutCreateWindow("EXAMqumian");
glutDisplayFunc(OnDisplay);
glutReshapeFunc(OnReshape);
Initialization();
glutMainLoop();
}
void Initialization()
{
glClearColor(1.0f,1.0f,1.0f,1.0f);
glEnable(GL_MAP1_VERTEX_3);
}
void OnDisplay()
{
GLfloat aCtrlPts[][3]={{-300,100,0.0},{-50,210,0.0},{-100,100,0.0},{50,150,0.0},{70,10,0.0},{-200,-100,0.0},{20,-230,0.0},{250,30,0.0},{300,-200,0.0}};
GLint n=9,i;
glClear(GL_COLOR_BUFFER_BIT);
glMap1f(GL_MAP1_VERTEX_3,0.0f,1.0f,3,n,*aCtrlPts);
glColor3f(1.0f,0.0f,0.0f);
glLineWidth(3);
glBegin(GL_LINE_STRIP);
for(i=0;i<=50;i++)
glEvalCoord1f(GLfloat(i/50.0));
glEnd();
glFlush();
//glutSwapBuffers();
}
void OnReshape(int w,int h)
{
GLfloat aspect;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);//当前矩阵为投影模式
glLoadIdentity();
if (w<=h)
{
aspect=h/w;
gluOrtho2D(-w/2,w/2,-h*aspect/2,h*aspect/2);
}
else
{
aspect=w/h;
gluOrtho2D(-w*aspect/2,w*aspect/2,-h/2,h/2);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
} 展开
1个回答
展开全部
这个很简单
因为你显示模式中设置的是双缓冲glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
显示回调函数中写的是单缓冲
glFlush();
所以应该把它改为
glutSwapBuffers();
或者显示模式改为glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
因为你显示模式中设置的是双缓冲glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
显示回调函数中写的是单缓冲
glFlush();
所以应该把它改为
glutSwapBuffers();
或者显示模式改为glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询