実行結果は、こんな感じ。
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "GL/glut.h"
GLfloat angle = 0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3d(1,1,1);
//線を描画
glBegin(GL_LINES);
glVertex3d(-1,0,0);
glVertex3d(1,0,0);
glVertex3d(0,-1,0);
glVertex3d(0,1,0);
glEnd();
//三角形を描画
//線が回らないようにPushMatrix
glPushMatrix();
glRotated(angle,0,1,0);
glBegin(GL_TRIANGLES);
glColor3d(1,0,0);
glVertex3d(-0.5,0,0);
glColor3d(0,1,0);
glVertex3d(0.5,0,0);
glColor3d(0,0,1);
glVertex3d(0.0,0.5,0);
glEnd();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void animate(void){
if(angle >= 360){
angle = 0;
}
else{
angle += 2;
}
Sleep(10);
glutPostRedisplay();
glutIdleFunc(animate);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
glutCreateWindow("TRIANGLE TEST");
glutPositionWindow(100,100);
glutIdleFunc(animate);
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/gl.h>
#include <GL/glu.h>
#include "GL/glut.h"
GLfloat angle = 0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3d(1,1,1);
//線を描画
glBegin(GL_LINES);
glVertex3d(-1,0,0);
glVertex3d(1,0,0);
glVertex3d(0,-1,0);
glVertex3d(0,1,0);
glEnd();
//三角形を描画
//線が回らないようにPushMatrix
glPushMatrix();
glRotated(angle,0,1,0);
glBegin(GL_TRIANGLES);
glColor3d(1,0,0);
glVertex3d(-0.5,0,0);
glColor3d(0,1,0);
glVertex3d(0.5,0,0);
glColor3d(0,0,1);
glVertex3d(0.0,0.5,0);
glEnd();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void animate(void){
if(angle >= 360){
angle = 0;
}
else{
angle += 2;
}
Sleep(10);
glutPostRedisplay();
glutIdleFunc(animate);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
glutCreateWindow("TRIANGLE TEST");
glutPositionWindow(100,100);
glutIdleFunc(animate);
glutDisplayFunc(display);
glutMainLoop();
}
0 件のコメント:
コメントを投稿