[]
任何人都可以通过2D中的转换(平移,旋转,缩放)帮助我制作对象,而无需使用内置命令进行转换(gltranslatef,glrotatef,glscalef)
答案 0 :(得分:0)
#include<GL\glut.h>
void molana_football();
int main(int argc,char * argv []){
glutInit(&argc, argv);
glutInitWindowSize(720, 480);
glutInitWindowPosition(50, 50);
glutCreateWindow("Football");
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutDisplayFunc(molana_football);
glClearColor(0.0, 0.0, 0.0, 0.0);
gluOrtho2D(0, 640, 0, 480);
glutMainLoop();
return 0;
} void molana_football()
{
glClear(GL_COLOR_BUFFER_BIT);
float x1, y1, x2, y2;
float angle;
double radius = 100 * 1.5;
x1 = 300 * 1.5, y1 = 200 * 1.5;
glBegin(GL_TRIANGLE_FAN);
glColor3f((GLfloat)1.0, (GLfloat)1.0, (GLfloat)1.0);
for (angle = 1.0f; angle<361.0f; angle += 0.2)
{
x2 = x1 + sin(angle)*radius;
y2 = y1 + cos(angle)*radius;
glVertex2i(x2, y2);
}
glEnd();
glBegin(GL_POLYGON);
glColor3f((GLfloat)1.0, (GLfloat)0.0, (GLfloat)0.0);
glVertex2i(300 * 1.5, 200 * 1.5);
glVertex2i(270 * 1.5, 190 * 1.5);
glVertex2i(265 * 1.5, 160 * 1.5);
glVertex2i(300 * 1.5, 150 * 1.5);
glVertex2i(320 * 1.5, 175 * 1.5);
glEnd();
int tx = 0; int ty = 10;
glBegin(GL_LINE_LOOP);
glVertex2i(300 * 1.5 + tx, 190 * 1.5 + ty);
glVertex2i(320 * 1.5 + tx, 230 * 1.5 + ty);
glEnd();
glBegin(GL_POLYGON);
glColor3f((GLfloat)0.9, (GLfloat)1.0, (GLfloat)0.0);
glVertex2i(320 * 1.5, 240 * 1.5);
glVertex2i(295 * 1.5, 260 * 1.5);
glVertex2i(310 * 1.5, 290 * 1.5);
glVertex2i(345 * 1.5, 285 * 1.5);
glVertex2i(350 * 1.5, 257 * 1.5);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(295 * 1.5 + tx, 250 * 1.5 + ty);
glVertex2i(270 * 1.5 + tx, 245 * 1.5 + ty);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(270 * 1.5 + tx, 180 * 1.5 + ty);
glVertex2i(250 * 1.5 + tx, 210 * 1.5 + ty);
glEnd();
glBegin(GL_POLYGON);
glColor3f((GLfloat)0.0, (GLfloat)0.0, (GLfloat)1.0);
glVertex2i(250 * 1.5, 220 * 1.5);
glVertex2i(270 * 1.5, 255 * 1.5);
glVertex2i(240 * 1.5, 270 * 1.5);
glVertex2i(215 * 1.5, 250 * 1.5);
glVertex2i(215 * 1.5, 225 * 1.5);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(215 * 1.5 + tx, 215 * 1.5 + ty);
glVertex2i(210 * 1.5 + tx, 160 * 1.5 + ty);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(265 * 1.5 + tx, 150 * 1.5 + ty);
glVertex2i(235 * 1.5 + tx, 145 * 1.5 + ty);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(235 * 1.5, 155 * 1.5);
glVertex2i(210 * 1.5, 170 * 1.5);
glVertex2i(206 * 1.5, 160 * 1.5);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(235 * 1.5, 155 * 1.5);
glVertex2i(245 * 1.5, 125 * 1.5);
glVertex2i(230 * 1.5, 130 * 1.5);
glVertex2i(206 * 1.5, 160 * 1.5);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(320 * 1.5 + tx, 165 * 1.5 + ty);
glVertex2i(350 * 1.5 + tx, 170 * 1.5 + ty);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(350 * 1.5 + tx, 247 * 1.5 + ty);
glVertex2i(370 * 1.5 + tx, 200 * 1.5 + ty);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(350 * 1.5, 180 * 1.5);
glVertex2i(370 * 1.5, 210 * 1.5);
glVertex2i(395 * 1.5, 190 * 1.5);
glVertex2i(390 * 1.5, 165 * 1.5);
glVertex2i(370 * 1.5, 155 * 1.5);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(370 * 1.5 + tx, 150 * 1.5 + ty);
glVertex2i(330 * 1.5 + tx, 95 * 1.5 + ty);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(300 * 1.5 + tx, 140 * 1.5 + ty);
glVertex2i(305 * 1.5 + tx, 110 * 1.5 + ty);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(245 * 1.5 + tx, 115 * 1.5 + ty);
glVertex2i(290 * 1.5 + tx, 90 * 1.5 + ty);
glEnd();
glBegin(GL_POLYGON);
glVertex2i(305 * 1.5, 120 * 1.5);
glVertex2i(330 * 1.5, 105 * 1.5);
glVertex2i(290 * 1.5, 100 * 1.5);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(310 * 1.5 + tx, 280 * 1.5 + ty);
glVertex2i(300 * 1.5 + tx, 290 * 1.5 + ty);
glEnd();
//scaling
int sx = 1; int sy = 2;
glBegin(GL_LINE_LOOP);
glVertex2i(240 * sx*1.5, 135 * sy*1.5);
glVertex2i(260 * sx*1.5, 145 * sy*1.5);
glEnd();
glEnd();
glFlush();
}