先開GLUT project,從老師上課軟體裡解壓縮檔案freelut
解壓縮後放置桌面,並將檔案複製改名,接著開啟GLUT project
#include <GL/glut.h>
void display()
{
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes"); /
glutDisplayFunc(display);
glutMainLoop();
}
複製前兩行
開始畫三角形
三角形三個頂點
更改三頂點的顏色
#include <GL/glut.h>
void display()
{
glBegin(GL_POLYGON);
glColor3f(1,0,0); glVertex2f(0,1);
glColor3f(0,1,0); glVertex2f(-1,-1);
glColor3f(0,0,1); glVertex2f(+1,-1);
glEnd();
glColor3f(1,1,0);
glutSolidTeapot( 0.3 );
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMainLoop();
}
皮卡丘??
找一張圖,用小畫家修改成200*200
用滴管吸,編輯顏色(/255)
畫圓
#include <GL/glut.h>
#include <math.h>
void myCircle(float r,float x,float y)
{
glBegin(GL_POLYGON);
for(float a=0;a<2*3.1415926535;a+=0.01)
{
glVertex2f(r*cos(a)+x,r*sin(a)+y);
}
glEnd();
}
void display()
{
glColor3f(1,0,1);myCircle(0.6,0,0);
glColor3f(1,0,0);myCircle(0.3,0.5,0.5);
glColor3f(0,1,0);myCircle(0.3,-0.5,0.5);
glColor3f(1,1,0);myCircle(0.3,-0.5,-0.5);
glColor3f(0,0,1);myCircle(0.3,0.5,-0.5);
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMainLoop();
}



















沒有留言:
張貼留言