| 5 | 1/1 | 返回列表 |
| 查看: 1152 | 回復: 8 | ||
| 當前只顯示滿足指定條件的回帖,點擊這里查看本話題的所有回帖 | ||
sukiyq木蟲 (小有名氣)
|
[求助]
OpenGL里全局變量引起的奇怪的問題
|
|
|
下邊是一個光照的OpenGL示例程序,運行有錯誤,把程序里完全沒有用到的全局變量“GLfloat light_pos[] = {1.0, 2.0, 3.0, 0.0};”一行刪除運行就正常了。這是為什么?明明這個全局變量并沒有用到,但是設置了它程序就會出錯,好奇怪。 #include GLfloat vertices[][3] = {{-1.0,-1.0,-1.0},{1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}}; GLfloat colors[][4] = {{1.0,0.0,0.0,0.5}, {0.0,1.0,1.0,0.5}, {1.0,1.0,0.0,0.5}, {0.0,1.0,0.0,0.5}, {0.0,0.0,1.0,0.5}, {1.0,0.0,1.0,0.5}}; GLfloat light_pos[] = {1.0, 2.0, 3.0, 0.0}; void polygon(int a, int b, int c , int d) { glColor4fv(colors[a]); if(colors[a][4] != 1.0) glDepthMask(GL_TRUE); else glDepthMask(GL_FALSE); glBegin(GL_POLYGON); glVertex3fv(vertices[a]); glVertex3fv(vertices); glVertex3fv(vertices[c]); glVertex3fv(vertices[d]); glEnd(); } void cube() { polygon(0,3,2,1); polygon(2,3,7,6); polygon(3,0,4,7); polygon(1,2,6,5); polygon(4,5,6,7); polygon(5,4,0,1); } static GLfloat theta[] = {0.0,0.0,0.0}; static GLint axis = 2; void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glRotatef(theta[0], 1.0, 0.0, 0.0); glRotatef(theta[1], 0.0, 1.0, 0.0); glRotatef(theta[2], 0.0, 0.0, 1.0); cube(); glutSwapBuffers(); } void spinCube() { theta[axis] += 2.0; if( theta[axis] > 360.0 ) theta[axis] -= 360.0; glutPostRedisplay(); } void mouse(int btn, int state, int x, int y) { if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN) axis = 0; if(btn==GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) axis = 1; if(btn==GLUT_RIGHT_BUTTON && state == GLUT_DOWN) axis = 2; } void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w, 2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0); else glOrtho(-2.0 * (GLfloat) w / (GLfloat) h, 2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); } void main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutCreateWindow("colorcube" ;glutReshapeFunc(myReshape); glutDisplayFunc(display); glutIdleFunc(spinCube); glutMouseFunc(mouse); glEnable(GL_DEPTH_TEST); /* Enable hidden--surface--removal */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glutMainLoop(); } |

木蟲 (小有名氣)

版主 (著名寫手)
木蟲 (小有名氣)

| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 303求調(diào)劑 +7 | DLkz1314. 2026-03-30 | 7/350 |
|
|---|---|---|---|---|
|
[考研] 調(diào)劑 +4 | GK72 2026-03-30 | 4/200 |
|
|
[考研] 279求調(diào)劑 +12 | j的立方 2026-03-29 | 12/600 |
|
|
[考研]
|
鐘llll 2026-03-26 | 5/250 |
|
|
[考研] 297求調(diào)劑 +17 | 田洪有 2026-03-26 | 18/900 |
|
|
[考研] 考研調(diào)劑 +5 | Sanmu-124 2026-03-26 | 5/250 |
|
|
[考研] 一志愿南昌大學324求調(diào)劑 +5 | hanamiko 2026-03-29 | 5/250 |
|
|
[考研] 085602 化工專碩 338分 求調(diào)劑 +12 | 路癡小琪 2026-03-27 | 12/600 |
|
|
[考研] 266分,求材料冶金能源化工等調(diào)劑 +7 | 哇呼哼呼哼 2026-03-27 | 9/450 |
|
|
[考研] 085602 307分 求調(diào)劑 +7 | 不知道叫什么! 2026-03-26 | 7/350 |
|
|
[考研] 086502化學工程342求調(diào)劑 +6 | 阿姨復古不過 2026-03-27 | 6/300 |
|
|
[有機交流]
高溫高壓反應求助
10+4
|
chibby 2026-03-25 | 4/200 |
|
|
[考研] 一志愿上海理工能源動力(085800)310分求調(diào)劑 +3 | zhangmingc 2026-03-27 | 4/200 |
|
|
[考研] 279 分 求調(diào)劑 +4 | 睡個好覺_16 2026-03-24 | 4/200 |
|
|
[考研] 調(diào)劑 +3 | 李嘉圖·S·路 2026-03-27 | 3/150 |
|
|
[考研] 求調(diào)劑 一志愿 本科 北科大 化學 343 +6 | 13831862839 2026-03-24 | 7/350 |
|
|
[考研] 機械學碩310分,數(shù)一英一,一志愿211本科雙非找調(diào)劑信息 +3 | @357 2026-03-25 | 3/150 |
|
|
[考研] 289求調(diào)劑 +17 | 碩星赴 2026-03-23 | 17/850 |
|
|
[考研] 一志愿天津大學339材料與化工求調(diào)劑 +3 | 江往賣魚 2026-03-26 | 3/150 |
|
|
[考研] 347求調(diào)劑 +4 | L when 2026-03-25 | 4/200 |
|