Created
February 18, 2014 07:09
-
-
Save anonymous/9065974 to your computer and use it in GitHub Desktop.
This file contains 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 <GL\glut.h> | |
void WindowSize(int , int ); //負責視窗及繪圖內容的比例 | |
void Keyboard(unsigned char , int, int ); //獲取鍵盤輸入 | |
void Display(float x,float y,float z); //描繪 | |
int main(int argc, char** argv) | |
{ | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); | |
glutInitWindowSize(400,400); | |
glutInitWindowPosition(600,80); | |
glutCreateWindow("這裡是視窗標題"); | |
glutReshapeFunc(WindowSize); | |
glutKeyboardFunc(Keyboard); | |
glutDisplayFunc(Display); | |
Display(1,1,0); | |
glutMainLoop(); | |
return 0; | |
} | |
void Display(float x,float y,float z) | |
{ | |
glClearColor(1.0, 1.0, 1.0, 1.0); //用白色塗背景 | |
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); | |
glMatrixMode(GL_MODELVIEW); | |
glLoadIdentity(); | |
gluLookAt(0,1,0,1,1,0,0,1,1); //視線的座標及方向 | |
glPointSize(10); | |
glBegin(GL_POINTS); | |
glColor3f( 1, 0, 0); | |
glVertex3f(x,y,z); | |
//glColor3f( 1, 0, 0); | |
//glVertex3f(1,2,0); | |
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