SDL

Das Forum fĂĽr Programmierer und Systemadmins. Von Shell-, Perl- und PHP-Scripts bis zur objektorientierten Programmierung mit C++.

SDL

Beitragvon Wolfi » Mo 27 Jan, 2003 18:07

<HTML>Ihr habt mich vor längerem so nett in die geheimnisse des LINKERS beim kompiliern gebracht *gg* (glut...)

doch jetz hab ich ein anderes problem

ich hab ein sdl win + SDL_OPENGL erstellt
hab aber eine fps von 1 bis 2 pro stunde

ihr kenn sicher cube (wouter.fov120.com/cube)
das kann ich aba spieln
sogar wenn ich selbst neukompilier

ich hab auch den init prozess von dem cube source kopiert..
was mach ich falsch???

nich böse sein weil ich hier meterlange posts mach

#include "main.h"

enum { ERR_SDL, ERR_OGL, ERR_GAME };

int scr_w = 1024;
int scr_h = 768;

bool quit_game;
bool hasoverbright = false;
int thread_count = 0;

Entity Player;

void keyrepeat(bool on)
{
SDL_EnableKeyRepeat(on ? SDL_DEFAULT_REPEAT_DELAY : 0,
SDL_DEFAULT_REPEAT_INTERVAL);
}

void fatalp(char *msg, ...)
{
fprintf(stderr, msg);
quit();
}

/*int minfps = 20; //LOL WOZU WENNS EH NED GEHT *fg*
int maxfps = 50;*/

int main(int argc, char **argv)
{
bool dedicated = false, listen = false;
int fs = SDL_FULLSCREEN;
char *sdesc = "", *ip = "", *master = NULL;
SDL_Surface *screen;

fprintf(stdout, "HENG Engine v0.01 startup\n");
//clear_log();

#define log(s) puts("Init: " s)

/* To remove the NOT USED warning */
dedicated=false; listen=false; fs=SDL_FULLSCREEN; sdesc=""; ip=""; master=NULL;

quit_game = false;

game_state = STATE_INIT;

for(int i = 1; i<argc; i++)
{
if(argv[i][0]=='-') switch(argv[i][1])
{
case 'c': fprintf(stdout, "Commandline C\n");
default: fprintf(stdout, "unknown commandline option\n");
}
else fprintf(stdout,"unknown commandline option\n");
}

const SDL_VideoInfo *videoInfo;
videoInfo = SDL_GetVideoInfo( );
int acc = 0;

log("SDL: Audio, Video");
if(SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) < 0) fatalp("SDL Error: %s\n", SDL_GetError());
//atexit(SDL_Quit);

log("SDL: Video");
if(SDL_InitSubSystem(SDL_INIT_VIDEO)<0) fatalp("SDL Error: %s\n", SDL_GetError());

log("SDL-GL");
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if((screen=SDL_SetVideoMode(scr_w, scr_h, 0, SDL_OPENGL | fs | acc))==NULL) fatalp("SDL Error: %s\n", SDL_GetError());

log("Video: Misc");
SDL_WM_SetCaption("HENG v0.01", NULL);
SDL_WM_GrabInput(SDL_GRAB_ON);
keyrepeat(false);
SDL_ShowCursor(0);


log("gl");
gl_init(scr_w, scr_h);

//log("gamethread");
//pthread_create(game_thread, NULL, game_thread_v, NULL);
//log("renderthread");
//pthread_create(render_thread, NULL, render_thread_v, NULL);

log("EVENT");
SDL_Event event;

int lasttype=0, lastbut=0;
int ignore = 0;

int lastmillis = 0;

int gamespeed = 100;

int curtime = 0;

HENG_MAP testmap;
testmap.width = 5;
testmap.height = 5;
testmap.length = 5;

testmap.cubes = new CUBE[5*5*5];
testmap.textures = new Texture[2];

Texture tex;
installtex(1, "data/stdtex/egypt_blocks1.jpg", tex.width, tex.height, tex);

installtex(2, "data/stdtex/egypt_blocks1.jpg", testmap.textures[0].width, testmap.textures[0].height, testmap.textures[0]);
installtex(3, "data/stdtex/egypt_stonewall1.jpg", testmap.textures[0].width, testmap.textures[0].height, testmap.textures[0]);


int TempTex[4];
TempTex[0] = tex.texID;
TempTex[1] = tex.texID;
TempTex[2] = tex.texID;
TempTex[3] = tex.texID;

int cub = 0;
for(float z = -2.0f; z < 2.0f; z++)
{
cub++;
for(float y = -2.0f; y < 2.0f; y++)
{
cub++;
for(float x = -2.0f; x < 2.0f; x++)
{
cub++;
testmap.cubes[cub] = map_cube_t(vec3(x, y, z-10.0f), vec3(0.0f, 0.0f, 0.0f),
testmap.textures[0].texID,
testmap.textures[0].texID,
TempTex);
}
}
}

testmap.nCubes = 5;
testmap.nTex = 2;

char *exts = (char *)glGetString(GL_EXTENSIONS);
if(strstr(exts, "GL_EXT_texture_env_combine")) hasoverbright = true;

Player.o = vec3(0.0f, 0.0f, 0.0f);

for(;;) /* The MAIN LOOP */
{
int millis = SDL_GetTicks()*gamespeed/100;
if(millis-lastmillis>200) lastmillis = millis-200;
else if(millis-lastmillis<1) lastmillis = millis-1;

curtime = millis - lastmillis;

static int frames = 0;
static float fps = 10.0f;

frames++;

fps = (1000.0f/curtime+fps*50)/51;
//fprintf(stdout, "FPS: %f\n", fps);

SDL_GL_SwapBuffers();

Player.floating = true;
Player.Move(curtime);

testmap.cubes[3].rot.x += 5.0f;
testmap.cubes[3].rot.y += 5.0f;
glBindTexture(GL_TEXTURE_2D, tex.texID);
gl_render_scene();
//gl_render_map(testmap);
//gl_render_test_triangle(curtime, tex);


lastmillis = millis;

while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
quit();
break;

case SDL_KEYDOWN:
keydown(event.key.keysym.sym);
break;
case SDL_KEYUP:
//keypress(event.key.keysym.sym, event.key.state==SDL_PRESSED, event.key.keysym.unicode);
keyup(event.key.keysym.sym);
break;

case SDL_MOUSEMOTION:
if(ignore) { ignore--; break; };
mousemove(event.motion.xrel, event.motion.yrel);
break;

case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
if(lasttype==event.type && lastbut==event.button.button) break; // why?? get event twice without it
//keypress(-event.button.button, event.button.state!=0, 0);
lasttype = event.type;
lastbut = event.button.button;
break;
};
}

if(quit_game)
quit();
}
quit();
exit(0);
return 0;
}


UND DIE GL INIT:
void gl_init(int width, int height)
{

#define fogvalues 0.5f, 0.6f, 0.7f, 1.0f

glViewport(0, 0, scr_w, scr_h); // For adding GL to SDL
glClearColor(fogvalues); // Clear the Screen GREY
glClearDepth(1.0); // Clear Depth FULL
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);

glEnable(GL_TEXTURE_2D);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0f, (float)width/(float)height, 0.01f, 100000.0f);
s_width = float(width);
s_height = float(height);

glMatrixMode(GL_MODELVIEW);

glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
}


also kann mier wer sagn was ich falsch mach bidde???
ich bin verzweifelt!

GreeZ
Wolfi</HTML>
Wolfi
 

ZurĂĽck zu PROGRAMMIER FORUM

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 21 Gäste