計算機圖學 Computer Graphics
- 主題:點、線、面、色彩
- 實作:OpenGL, GLUT, WebGL
- 親手打早第一個圖學程式
// call lib GLUT extention
#include <GL/glut.h>
void display()
{
glClearColor(0.5,0.4,0,0);
// setting the clear color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// use the COLOR to clear the window background (it is an active)
glColor3f(1,1,0.5);
// 3 color parameter using float type (0.0-1.0)
glutSolidTeapot(0.3);
// draw a teapot on the screen
glBegin(GL_POLYGON);
// start to draw ploygon = 多邊形
glVertex3f(1, -1, 0);
glVertex3f(-1, 1, 0);
glVertex3f(-1, 0, 0);
// 3f : x, y, z 3 parameters
glEnd();
// end an draw
glutSwapBuffers();
// clear the buffer, avoid 畫面閃爍的問題
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
// start to use "GLUT". Catch above parameters
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
// setting display mode
glutCreateWindow("GLUT Shapes");
// create GLUT 3D window
glutDisplayFunc(display);
glutMainLoop();
// let main() function keep running
}
沒有留言:
張貼留言