[問題] SDL + OPENGL 每次執行結果不一樣

看板C_and_CPP (C/C++)作者 (難過..錢!!)時間16年前 (2009/04/17 23:09), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
程式碼網址 http://src.wtgstudio.com/?TviOWy 其實就只是用SDL做出視窗, 用openGL繪圖, 繪的也不是什麼特別的圖, 不過就是sierpinski triangle 我也做出來這個功能了, 他會如我所想的動 重點來了!! 我每次執行它的結果都不一樣!! 通常情況是第一次 compiler + execute 會很正常的動, 第二次會一片黑, 黑一陣子之後會又開始動, 大部分我都是切換視窗一陣子又回來才看到他在慢慢動 我有用到rand()函數, 但是沒有改變seed, 應該不會這樣才對啊 程式架構是一開始initial everything, 然後進一個無窮迴圈 按esc鍵可以跳出, 每次會多畫一個點 作業系統XP, IDE是Dev-C++ 請問有人有辦法說明一下嘛, 萬分感激 謝謝 下面是BBS的 code, 共59行 #include <SDL/SDL.h> #include <gl/gl.h> #include "SDL/SDL_opengl.h" /* PLEASE NOTE: the program will require SDL.dll which is located in dev-c++'s dll directory. You have to copy it to you program's home directory or the path. */ using namespace std; int main(int argc, char *argv[]){ SDL_Event event; SDL_Init( SDL_INIT_EVERYTHING ); SDL_SetVideoMode(510, 510, 32, SDL_OPENGL); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // glClearDepth(1.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 510, 0, 510, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); typedef GLfloat point2[2]; point2 vertices[3] = {{0.0, 0.0}, {250.0, 500.0}, {500.0, 0.0}}; point2 p = {100.0, 100.0}; glBegin(GL_POINTS); glColor3f( 1.0f, 1.0f, 1.0f ); glVertex2fv(p); glEnd(); glLoadIdentity(); int done; int k = 0; int j = 0; for(done = 0; !done;){ k++; j = rand()%3; p[0] = (p[0] + vertices[j][0]) / 2.0; p[1] = (p[1] + vertices[j][1]) / 2.0; glBegin(GL_POINTS); glColor3f( 1.0f, 1.0f, 1.0f ); glVertex2fv(p); glEnd(); glLoadIdentity(); SDL_GL_SwapBuffers(); SDL_PollEvent(&event); if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; } SDL_Quit(); return(0); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.83.212 cactusseed:轉錄至看板 Programming 04/22 18:02
文章代碼(AID): #19w9kLuG (C_and_CPP)
文章代碼(AID): #19w9kLuG (C_and_CPP)