OpenGL 为什么显示不出来图形,只显示出来了背景?求大神指导!
//#defineGLUT_DISBALE_ATEXIT_HACK#defineGLUT_DISABLE_ATEXIT_HACK#include<windows.h>#i...
//#define GLUT_DISBALE_ATEXIT_HACK
#define GLUT_DISABLE_ATEXIT_HACK
#include<windows.h>
#include<GL/GL.H>
#include<GL/glut.h>
//#include<GL/GLU.H>
#include<math.h>
#define PI 3.1415926
//清除窗口初始化
void init()
{
glClearColor(0.0f,0.0f,0.0f,0.0f);
glShadeModel(GL_FLAT);
}
/*改变大小*/
void ChangeSize(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)w,0.0,(GLdouble)h);
}
GLfloat R=0.5f;
//绘制物体
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
//画坐标轴
glBegin(GL_LINES);
glVertex2f(-1.0f,0.0f);
glVertex2f(1.0f,0.0f);
glVertex2f(0.0f,1.0f);
glVertex2f(0.0f,-1.0f);
glEnd();
//画圆....
glBegin(GL_LINE_LOOP);
for(int i=0;i<=1000;++i)
{
glVertex2f(R*cos(2*PI/1000*i),R*sin(2*PI/1000*i));
}
glEnd();
glFlush();
}
//定义窗口
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(200,200);
glutInitWindowSize(300,300);
glutCreateWindow("draw circle");
init();
//glutDisplayFunc(display);
glutReshapeFunc(ChangeSize);
glutDisplayFunc(display);
glutIdleFunc(display);
//glutIdleFunc();
glutMainLoop();
return 0;
} 展开
#define GLUT_DISABLE_ATEXIT_HACK
#include<windows.h>
#include<GL/GL.H>
#include<GL/glut.h>
//#include<GL/GLU.H>
#include<math.h>
#define PI 3.1415926
//清除窗口初始化
void init()
{
glClearColor(0.0f,0.0f,0.0f,0.0f);
glShadeModel(GL_FLAT);
}
/*改变大小*/
void ChangeSize(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)w,0.0,(GLdouble)h);
}
GLfloat R=0.5f;
//绘制物体
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
//画坐标轴
glBegin(GL_LINES);
glVertex2f(-1.0f,0.0f);
glVertex2f(1.0f,0.0f);
glVertex2f(0.0f,1.0f);
glVertex2f(0.0f,-1.0f);
glEnd();
//画圆....
glBegin(GL_LINE_LOOP);
for(int i=0;i<=1000;++i)
{
glVertex2f(R*cos(2*PI/1000*i),R*sin(2*PI/1000*i));
}
glEnd();
glFlush();
}
//定义窗口
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(200,200);
glutInitWindowSize(300,300);
glutCreateWindow("draw circle");
init();
//glutDisplayFunc(display);
glutReshapeFunc(ChangeSize);
glutDisplayFunc(display);
glutIdleFunc(display);
//glutIdleFunc();
glutMainLoop();
return 0;
} 展开
展开全部
//#define GLUT_DISBALE_ATEXIT_HACK
#define GLUT_DISABLE_ATEXIT_HACK
#include<windows.h>
#include<GL/GL.H>
#include<GL/glut.h>
//#include<GL/GLU.H>
#include<math.h>
#define PI 3.1415926
//清除窗口初始化
void init()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_FLAT);
}
/*改变大小*/
void ChangeSize(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h);
gluPerspective(60, 1, 0.1, 100); // 设置投影转换
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, -2, 0, 0, 0, 0, 1, 0); // 设置视点
}
GLfloat R = 0.5f;
//绘制物体
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.0f, 0.0f);
//画坐标轴
glBegin(GL_LINES);
glVertex2f(-1.0f, 0.0f);
glVertex2f(1.0f, 0.0f);
glVertex2f(0.0f, 1.0f);
glVertex2f(0.0f, -1.0f);
glEnd();
//画圆....
glBegin(GL_LINE_LOOP);
for (int i = 0; i <= 1000; ++i)
{
glVertex2f(R*cos(2 * PI / 1000 * i), R*sin(2 * PI / 1000 * i));
}
glEnd();
glFlush();
}
//定义窗口
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(200, 200);
glutInitWindowSize(300, 300);
glutCreateWindow("draw circle");
init();
//glutDisplayFunc(display);
glutReshapeFunc(ChangeSize);
glutDisplayFunc(display);
glutIdleFunc(display);
//glutIdleFunc();
glutMainLoop();
return 0;
}
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询