我正在为一个大学项目重建旧游戏“Chuckie egg”,我使用下面的代码绘制了这个角色,但是我不确定在glBegin(?)中使用什么类型来为对象着色in。
我已经尝试了,GL_QUADS,GL_TRIANGLE_FAN,GL_TRIANGLE_STRIP和GL_QUAD_STRIP,但唯一一个没有错误显示的工作是GL_LINE_LOOP,但这当然不会为整个形状着色。
有谁知道如何解决这个问题?
void drawMan(void){
//main body outline
glBegin(GL_LINE_LOOP);
//set our colour
glColor3ub(255, 255, 0); // yellow
glVertex2f(-0.25f, 1.0f);
glVertex2f(0.25f, 1.0f);
glVertex2f(0.25f, 0.875f);
glVertex2f(0.5f, 0.875f);
glVertex2f(0.5f, 0.75f);
glVertex2f(1.0f, 0.75f);
glVertex2f(1.0f, 0.625f);
glVertex2f(0.5f, 0.625f);
glVertex2f(0.5f, 0.375f);
glVertex2f(0.0f, 0.375f);
glVertex2f(0.0f, 0.25f);
glVertex2f(0.25f, 0.25f);
glVertex2f(0.25f, 0.125f);
glVertex2f(0.5f, 0.125f);
glVertex2f(0.5f, 0.0f);
glVertex2f(0.75f, 0.0f);
glVertex2f(0.75f, -0.5f);
glVertex2f(0.5f, -0.5f);
glVertex2f(0.5f, -0.625f);
glVertex2f(0.25f, -0.625f);
glVertex2f(0.25f, -0.75f);
glVertex2f(0.0f, -0.75f);
glVertex2f(0.0f, -0.875f);
glVertex2f(0.25f, -0.875f);
glVertex2f(0.25f, -1.0f);
glVertex2f(-0.25f, -1.0f);
glVertex2f(-0.25f, -0.625f);
glVertex2f(-0.5f, -0.625f);
glVertex2f(-0.5f, -0.5f);
glVertex2f(-0.75f, -0.5f);
glVertex2f(-0.75f, 0.0f);
glVertex2f(-0.5f, 0.0f);
glVertex2f(-0.5f, 0.125f);
glVertex2f(-0.25f, 0.125f);
glVertex2f(-0.25f, 0.375f);
glVertex2f(-0.5f, 0.375f);
glVertex2f(-0.5f, 0.625f);
glVertex2f(-1.0f, 0.625f);
glVertex2f(-1.0f, 0.75f);
glVertex2f(-0.5f, 0.75f);
glVertex2f(-0.5f, 0.85f);
glVertex2f(-0.25f, 0.85f);
//glVertex2f(-0.25f, 1.0f);
glEnd();
//eyes
glBegin(GL_LINE_LOOP);
glColor3ub(0, 0, 0); // black
glVertex2f(0.0f, 0.625f);
glVertex2f(0.25f, 0.625f);
glVertex2f(0.25f, 0.5f);
glVertex2f(0.0f, 0.5f);
glEnd();
//arm
glBegin(GL_LINE_LOOP);
glColor3ub(0, 0, 0); // black
glVertex2f(-0.25f, 0.0f);
glVertex2f(0.0f, 0.0f);
glVertex2f(0.0f, -0.5f);
glVertex2f(-0.25f, -0.5f);
glEnd();}
答案 0 :(得分:3)
你不能只是绘制一个随机轮廓并为其着色。你必须正确地对你的形状进行三角测量。
实际上,这是一个可以输出合理几何图形或使用纹理的绘图包的工作。