作者cactusseed (难过..钱!!)
看板C_and_CPP
标题[问题] SDL + OPENGL 每次执行结果不一样
时间Fri Apr 17 23:09:08 2009
程式码网址
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