註冊github.com
並新增Repositories 2021graphics
上傳程式到github
1. 先在codeblocks開始OpenGL,命名week03
2.下載Freeglut
3.在codeblocks開啟GLUT
4.上傳到github
畫一個黃色的圓
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,0);
glutSolidSphere(0.5,30,30);
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week03-circle");
glutDisplayFunc( display );
glutMainLoop();
}
劃一個黃色的橢圓
#include <GL/glut.h>
#include <math.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,0);
glBegin(GL_POLYGON);
for(int i=0; i<30; i++){
float a=3.1415926*2/30*i;
glVertex2f(0.5+0.1*cos(a), 0.2*sin(a));
}
glEnd();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week03-circle");
glutDisplayFunc( display );
glutMainLoop();
}










沒有留言:
張貼留言