opengl 一个界面里画了个圆和一个三角形 为什仫不能同时显示 求大神你指导 15
opengl一个界面里画了个圆和一个三角形为什仫不能同时显示求大神你指导#include"stdafx.h"#defineGLUT_DISABLE_ATEXIT_HACK...
opengl 一个界面里画了个圆和一个三角形 为什仫不能同时显示 求大神你指导
#include "stdafx.h"
#define GLUT_DISABLE_ATEXIT_HACK
#include <GL/glut.h>
#include <math.h>
const int n = 1000;
const GLfloat R = 0.5f;
const GLfloat Pi = 3.1415926536f;
void init(void)
{
glClearColor(0.8705, 0.9019, 0.8431, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
void myDisplay()
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
for (i = 0; i<n; i++)
glVertex2f(R*cos(2 * Pi / n*i), R*sin(2 * Pi / n*i));
glEnd();
glColor3f(0.635, 0.768, 0.533);
glBegin(GL_POLYGON);
glVertex2i(50, 63);
glVertex2i(20, 63);
glVertex2i(35, 80);
glEnd();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("圆");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}
想出来是这样的 展开
#include "stdafx.h"
#define GLUT_DISABLE_ATEXIT_HACK
#include <GL/glut.h>
#include <math.h>
const int n = 1000;
const GLfloat R = 0.5f;
const GLfloat Pi = 3.1415926536f;
void init(void)
{
glClearColor(0.8705, 0.9019, 0.8431, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
void myDisplay()
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
for (i = 0; i<n; i++)
glVertex2f(R*cos(2 * Pi / n*i), R*sin(2 * Pi / n*i));
glEnd();
glColor3f(0.635, 0.768, 0.533);
glBegin(GL_POLYGON);
glVertex2i(50, 63);
glVertex2i(20, 63);
glVertex2i(35, 80);
glEnd();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("圆");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}
想出来是这样的 展开
1个回答
推荐于2017-07-01 · 知道合伙人互联网行家
关注
展开全部
你的代码在main中没有调用init(),半径0.5 太小了吧。。。
#define GLUT_DISABLE_ATEXIT_HACK
#include <GL/glut.h>
#include <math.h>
const int n = 1000;
const GLfloat Org = 80.0f; //原点xy都是80吧,省事儿点。如原点是0的话
//就会只画出四分之一圆
const GLfloat R = 10.0f; //半径大点,容易看到。。。
const GLfloat Pi = 3.1415926536f;
void init(void)
{
glClearColor(0.8705, 0.9019, 0.8431, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 100.0, 0.0, 100.0);
}
void myDisplay()
{
int i;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.935, 0.768, 0.533);
glBegin(GL_POLYGON);
for (i = 0; i<n; i++)
glVertex2f(Org+R*cos(2 * Pi / n*i), Org+R*sin(2 * Pi / n*i));
glEnd();
glColor3f(0.635, 0.768, 0.533);
glBegin(GL_POLYGON);
glVertex2i(50, 63);
glVertex2i(20, 63);
glVertex2i(35, 80);
glEnd();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("圆");
init(); //记得调用初始化函数
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询