Page 2 of 3

Re: Working on 3D OpenGL/C Game Engine...

Posted: Wed Apr 21, 2004 7:46 pm
by erek
i'm not a dumbass, apparently my browser has the photograph cached

,dumbass.

Re: Working on 3D OpenGL/C Game Engine...

Posted: Wed Apr 21, 2004 7:48 pm
by erek
http://frozenarctic.com/erek/Snickers.jpg

Re: Working on 3D OpenGL/C Game Engine...

Posted: Thu Apr 22, 2004 9:06 am
by Speed
Yeah, you're going to run mad fps on an object like this. Put some textures on it, fifteen heads on the screen, and some background landscaping, then see what you come up with. It looks good as is, but can you really pull useful information from a test like this?

Re: Working on 3D OpenGL/C Game Engine...

Posted: Thu Apr 22, 2004 10:31 am
by MrBlack
For any good game, you need to go with fewer faces. The more objects you add to the environment, the more faces, the slower it will get. You nered to optimize each object by using the fewest faces you can possibly get away with. There is no need to get into so much detail with a model, as texturing can, and usually will, cover up any problems that might arise from the low poly count.

Re: Working on 3D OpenGL/C Game Engine...

Posted: Thu Apr 22, 2004 11:40 am
by Hobo_Bill
But you should look into other aspects to use your skills in, Erek, ie: special effects / graphic design for movies and such..

Re: Working on 3D OpenGL/C Game Engine...

Posted: Thu Apr 22, 2004 5:00 pm
by erek
well, i worked with opengl several times before, and each time i got bored and discouraged really fast, but each time i started working on it, i got "slightly" more work done. well this time i got really sick, and was out of school recently for friday, the whole weekend, and monday, and so while i was sick as a dog, i decided to give it a shot again, but not to give up so easily.. and i guess i pulled off something half decent this time, i plan on working on creating a game engine, and maybe a more accurate physics engine. it would be cool if you guys could help me with some ideas and stuff.. i gotta go, my nose is running and i feel like shit...

Re: Working on 3D OpenGL/C Game Engine...

Posted: Fri Apr 23, 2004 3:18 pm
by MrBlack
Erek, I've got plenty of ideas. If you actually follow through on this, I'll help out ;)



ICQ me.

Re: Working on 3D OpenGL/C Game Engine...

Posted: Sat Apr 24, 2004 12:26 pm
by erek
Erek, I've got plenty of ideas. If you actually follow through on this, I'll help out ;)



ICQ me.



81888800

Re: Working on 3D OpenGL/C Game Engine...

Posted: Sat Apr 24, 2004 12:30 pm
by erek
Yeah, you're going to run mad fps on an object like this. Put some textures on it, fifteen heads on the screen, and some background landscaping, then see what you come up with. It looks good as is, but can you really pull useful information from a test like this?



well what usually makes an object in games look more complex than it actually is, is the textures.. without the textures sometimes the object model looks like a generalization of the obect. my model was designed to look really close to a real monkey without textures yet... and it has a significant amount of polygons, i'd say almost 80,0000..

Re: Working on 3D OpenGL/C Game Engine...

Posted: Sun Apr 25, 2004 9:19 pm
by erek
well what usually makes an object in games look more complex than it actually is, is the textures.. without the textures sometimes the object model looks like a generalization of the obect. my model was designed to look really close to a real monkey without textures yet... and it has a significant amount of polygons, i'd say almost 80,0000..





i just spent a huge amount of time rewriting the entire thing to get more speed:



#include

#include

#include

#include

#include



typedef struct { float x,y,z; } quad_vert;

typedef struct { float x,y,z; } quad_norm;

typedef struct { float x,y,z; } tri_vert;

typedef struct { float x,y,z; } tri_norm;

struct { int tri_verts, tri_norms, quad_verts, quad_norms, models; }

number;



struct window{

int width;

int height;

int bpps;

int flags;

};



int mousex;

int mousey;

char *key;

SDL_Event event;

GLfloat i;

GLfloat n;



void input(struct window *win){



SDL_Event event;



while ( SDL_PollEvent(&event) ) {

switch (event.type) {

case SDL_MOUSEMOTION:



mousex=event.motion.x;

mousey=event.motion.y;

break;

case SDL_MOUSEBUTTONDOWN:



SDL_Quit();

exit(0);



break;

case SDL_KEYDOWN:



key=SDL_GetKeyName(event.key.keysym.sym);



switch( event.key.keysym.sym ){

case SDLK_LEFT:

i--;

break;

case SDLK_RIGHT:

i++;

break;

case SDLK_UP:

n++;

break;

case SDLK_DOWN:

n--;

break;

default:

break;}





}

}



}







/* Arrays for Quads/Triangles */

quad_vert **quad_v;

quad_norm **quad_n;

tri_vert **tri_v;

tri_norm **tri_n;





int LoadModel(){



#define FILE_NAME "object1.c"

FILE *fp=fopen(FILE_NAME, "r");

char *txt = malloc(1024);

number.models=2;

int counter;



tri_n = malloc(number.models * sizeof *tri_n);

tri_v = malloc(number.models * sizeof *tri_v);

quad_v = malloc(number.models * sizeof *quad_v);

quad_n = malloc(number.models * sizeof *quad_n);



/* TRIANGLES */

while(!feof(fp)){

fscanf(fp, "%s",txt);



if(strcmp(txt,"TRI")==0){



//printf("\nTriangles %d:\n",t);

for(counter=0; counter!=3;counter++)

{



/* Normal 1 */

fscanf(fp, "%s",txt);

if(strcmp(txt,"n")==0){



number.tri_norms++;



tri_n[number.models-1] = realloc(tri_n[number.models-1], (number.tri_norms * sizeof *tri_n[number.models-1]));

fscanf(fp, "%f %f %f",&tri_n[number.models-1][number.tri_norms-1].x,&tri_n[number.models-1][number.tri_norms-1].y,&tri_n[number.models-1][number.tri_norms-1].z);



//printf("Normal %d: %.10f %.10f %.10f\n",number.tri_norms-1,tri_n[number.models-1][number.tri_norms-1].x,tri_n[number.models-1][number.tri_norms-1].y,tri_n[number.models-1][number.tri_norms-1].z);



}





/* Vertex 1 */

fscanf(fp, "%s",txt);

if(strcmp(txt,"v")==0){



number.tri_verts++;



tri_v[number.models-1] = realloc(tri_v[number.models-1], (number.tri_verts * sizeof *tri_v[number.models-1]));

fscanf(fp, "%f %f %f",&tri_v[number.models-1][number.tri_verts-1].x,&tri_v[number.models-1][number.tri_verts-1].y ,&tri_v[number.models-1][number.tri_verts-1].z);

// printf("Vertex %d: %.10f %.10f %.10f\n",number.tri_verts-1,tri_v[number.models-1][number.tri_verts-1].x,tri_v[number.models-1][number.tri_verts-1].y,tri_v[number.models-1][number.tri_verts-1].z);

}



}}



}



fclose(fp);

fopen(FILE_NAME, "r");



/* QUAD */

while(!feof(fp)){

fscanf(fp, "%s",txt);



if(strcmp(txt,"QUAD")==0){



//printf("\nQuads:\n");

for(counter=0; counter!=4;counter++)

{



/* Normal 1 */

fscanf(fp, "%s",txt);

if(strcmp(txt,"n")==0){



number.quad_norms++;



quad_n[number.models-1] = realloc(quad_n[number.models-1], (number.quad_norms * sizeof *quad_n[number.models-1]));

fscanf(fp, "%f %f %f\n", &quad_n[number.models-1][number.quad_norms-1].x, &quad_n[number.models-1][number.quad_norms-1].y, &quad_n[number.models-1][number.quad_norms-1].z);



//printf("Normal %d: %.10f %.10f %.10f\n",number.quad_norms-1, quad_n[number.models-1][number.quad_norms-1].x, quad_n[number.models-1][number.quad_norms-1].y, quad_n[number.models-1][number.quad_norms-1].z);

}



/* Vertex 1 */

fscanf(fp, "%s",txt);

if(strcmp(txt,"v")==0){



number.quad_verts++;



quad_v[number.models-1] = realloc(quad_v[number.models-1], (number.quad_verts * sizeof *quad_v[number.models-1]));

fscanf(fp, "%f %f %f\n", &quad_v[number.models-1][number.quad_verts-1].x, &quad_v[number.models-1][number.quad_verts-1].y, &quad_v[number.models-1][number.quad_verts-1].z);



//printf("Normal %d: %.10f %.10f %.10f\n",number.quad_verts-1, quad_v[number.models-1][number.quad_verts-1].x, quad_v[number.models-1][number.quad_verts-1].y, quad_v[number.models-1][number.quad_verts-1].z);



}



}}



}



free(txt);

fclose(fp);

}



void GenWindow(struct window *win){



win->width=1024;

win->height=768;

win->bpps=24;



SDL_Init(SDL_INIT_VIDEO);



SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);

SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,24);



SDL_SetVideoMode(win->width,win->height,win->bpps,SDL_OPENGL|SDL_FULLSCREEN);



glClearColor( 0, 0, 0, 0 );



glViewport(0,0,win->width,win->height);



glMatrixMode( GL_PROJECTION );



glLoadIdentity( );



printf("\n%dx%d@%d Window Created.\n", win->width, win->height, win->bpps);



}



void scene(struct window *win){



register float ratio = (float) win->width / (float) win->height;







glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glMatrixMode( GL_MODELVIEW );

glLoadIdentity( );





gluPerspective(50.0, ratio, 1.0, 10000);





GLfloat lightAmbient[] = {1.0f, 0.0f, 0.0f, 1.0f} ;



glEnable(GL_LIGHTING) ;

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lightAmbient) ;

GLfloat lightPosition[] = {9.7f, 9.0f, 0.0f, 0.0f} ;

GLfloat lightDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f} ;

GLfloat lightSpecular[] = {1.0f, 1.0f, 1.0f, 1.0f} ;



glEnable(GL_LIGHT0) ;

glLightfv(GL_LIGHT0, GL_POSITION,lightPosition) ;

glLightfv(GL_LIGHT0, GL_AMBIENT,lightAmbient) ;

glLightfv(GL_LIGHT0, GL_DIFFUSE,lightDiffuse) ;

glLightfv(GL_LIGHT0, GL_SPECULAR,lightSpecular) ;



glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glEnable(GL_LINE_SMOOTH);

glShadeModel(GL_SMOOTH);

glDisable(GL_CULL_FACE);

glEnable(GL_DEPTH_TEST);

glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);





glTranslatef(i,n,-3.0f);



glRotatef(1.0f+mousex,0.0f,1.0f,0.0f);

glRotatef(1.0f+mousey,1.0f,0.0f,0.0f);





/* triangles */

glEnableClientState(GL_NORMAL_ARRAY);

glNormalPointer(GL_FLOAT, 0, (GLvoid *)tri_n[1]);



glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(3, GL_FLOAT,0, (GLvoid *)tri_v[1]);

glDrawArrays(GL_TRIANGLES,0,number.tri_verts);





glDisableClientState(GL_VERTEX_ARRAY);



/* quads */

glNormalPointer(GL_FLOAT, 0, (GLvoid *)quad_n[1]);



glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(3, GL_FLOAT,0,(GLvoid *)quad_v[1]);

glDrawArrays(GL_QUADS,0,number.quad_verts);



glDisableClientState(GL_NORMAL_ARRAY);

glDisableClientState(GL_VERTEX_ARRAY);





SDL_GL_SwapBuffers();



}



int main(int argc, char* argv[]){





struct window win;



LoadModel();

GenWindow(&win);



SDL_EnableKeyRepeat(100,SDL_DEFAULT_REPEAT_INTERVAL);

SDL_ShowCursor(SDL_DISABLE);



do{



input(&win);

scene(&win);



}while(1);



return 0;}