Created
March 2, 2014 09:08
-
-
Save anonymous/9303923 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include "glut.h" | |
| void WindowSize(int , int ); //負責視窗及繪圖內容的比例 | |
| void Keyboard(unsigned char ,int, int ); //獲取鍵盤輸入 | |
| void Display(void); //描繪 | |
| int main(int argc, char** argv) | |
| { | |
| glutInit(&argc, argv); | |
| glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); | |
| glutInitWindowSize(400,400); //視窗長寬 | |
| glutInitWindowPosition(600,80); //視窗左上角的位置 | |
| glutCreateWindow("這裡是視窗標題"); //建立視窗 | |
| //下面三個是用來指定Callback函數 | |
| glutReshapeFunc(WindowSize); | |
| glutKeyboardFunc(Keyboard); | |
| glutDisplayFunc(Display); | |
| glutMainLoop(); | |
| return 0; | |
| } | |
| void Display(void) | |
| { | |
| glClearColor(1, 1, 1, 1.0); //用白色塗背景 | |
| glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); | |
| glMatrixMode(GL_MODELVIEW); | |
| glLoadIdentity(); | |
| gluLookAt(10,10,10,0,0,0,0,1,0); //視線的座標及方向 | |
| glPointSize(10); | |
| glBegin(GL_POINTS); | |
| glColor3f( 1, 0, 0); | |
| glVertex3f(0,0,0); | |
| glEnd(); | |
| glBegin(GL_LINES); | |
| glColor3f( 1, 0, 0); | |
| glVertex3f(-100,0,0); | |
| glVertex3f(100,0,0); | |
| glColor3f( 1, 0, 0); | |
| glVertex3f(0,-100,0); | |
| glVertex3f(0,100,0); | |
| glColor3f( 1, 0, 0); | |
| glVertex3f(0,0,-100); | |
| glVertex3f(0,0,100); | |
| glEnd(); | |
| glutSwapBuffers(); | |
| } | |
| void Keyboard(unsigned char key, int x, int y) | |
| { | |
| printf("你所按按鍵的碼是%x\t此時視窗內的滑鼠座標是(%d,%d)\n", key, x, y); | |
| } | |
| void WindowSize(int w, int h) | |
| { | |
| printf("目前視窗大小為%dX%d\n",w,h); | |
| glViewport(0, 0, w, h); //當視窗長寬改變時,畫面也跟著變 | |
| glMatrixMode(GL_PROJECTION); | |
| glLoadIdentity(); | |
| glOrtho(-10,10,-10,10,-10,10); //正交投影 | |
| glMatrixMode(GL_MODELVIEW); | |
| glLoadIdentity(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment