1.
開codeblock-file-new-project-GLUT project
...選桌面 檔案名稱week02_GLUT_first
將上課用軟體freeglut複製至桌面
進lib 複製libfreeglut_static.a 重新命名libglut32.a
glut location選擇freeglut
#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();
}
2.
glColor3f(0,1,0);
glutSolidTeapot( 0.5 ); ///會出現大綠茶壺
glColor3f(1,1,0);///小茶壺會變黃色
glBegin(GL_POLYGON);
glVertex2d( 0, 1);
glVertex2d(-1,-1);
glVertex2d(+1,-1);
glEnd();
glColor3f(1,0,0); glVertex2f( 0, 1);///紅色頂點
glColor3f(0,1,0); glVertex2f(-1,-1);///綠色頂點
glColor3f(0,0,1); glVertex2f(-1,-1);///藍色頂點
程式碼
#include <GL/glut.h>
void display()
{
glColor3f(247/255.0,247/255.0,247/255.0);
glBegin(GL_POLYGON);
glVertex2f(1,1);
glVertex2f(-1,1);
glVertex2f(-1,-1);
glVertex2f(1,-1);
glEnd();
glColor3f(244/255.0,209/255.0,33/255.0);
glBegin(GL_POLYGON);
glVertex2f((45-100)/100.0,-(134-100)/100.0);
glVertex2f((36-100)/100.0,-(171-100)/100.0);
glVertex2f((108-100)/100.0,-(179-100)/100.0);
glVertex2f((104-100)/100.0,-(117-100)/100.0);
glEnd();
glutSwapBuffers();
}
執行出現黃白視窗
3.
#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.14159; 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();
}
沒有留言:
張貼留言