diff --git a/CHANGES b/CHANGES index db76595..b7e66eb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +11 November 2000 ++ Got opengl sorta working, when I should be working on my + OS project involving semaphores. Oops. + 2 November 2000 + Continued re-writing the level_1 engine that I started last week. + Re-wrote frame limiter. Managed to make it a lot less jumpy. diff --git a/Makefile.inc b/Makefile.inc index 3a0c804..6551f3e 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -42,9 +42,9 @@ CURSES_LIBS= -lncurses # # Uncomment the following for opengGL # -#OPENGL_TARGET= opengl_svmwgraph.o -#OPENGL_FLAGS=-DOPENGL_TARGET -#OPENGL_LIBS= -L/usr/X11R6/lib -lX11 -lICE -lXmu -lGL -lGLU -lglut +OPENGL_TARGET= opengl_svmwgraph.o +OPENGL_FLAGS=-DOPENGL_TARGET +OPENGL_LIBS= -L/usr/X11R6/lib -lX11 -lICE -lXmu -lGL -lGLU ############################## diff --git a/TODO b/TODO index 4093efc..38354a1 100644 --- a/TODO +++ b/TODO @@ -17,3 +17,5 @@ SVMWGraph todo: Known Bugs: 8bpp palette switching not as smooth as it could be. Volume controls on option menu don't do anything yet + I get higher FPS on a 486 than my k6-2+! Need to figure this out. + Frame limited code is limited. Need to think about this some more. diff --git a/level_1.c b/level_1.c index b002caa..58ec021 100644 --- a/level_1.c +++ b/level_1.c @@ -590,6 +590,7 @@ void LevelOneEngine(tb1_state *game_state) { if (add_another_enemy(0,game_state)==LEVEL_OVER) { game_state->level=2; levelover=1; + return; } } @@ -782,8 +783,7 @@ void LevelOneEngine(tb1_state *game_state) { } /* The little opener before Level 1 */ -void LevelOneLittleOpener(tb1_state *game_state) -{ +void LevelOneLittleOpener(tb1_state *game_state) { vmwSprite *ship1,*ship2; int i; diff --git a/svmwgraph/opengl_svmwgraph.c b/svmwgraph/opengl_svmwgraph.c index 48b75d5..bb7ec27 100644 --- a/svmwgraph/opengl_svmwgraph.c +++ b/svmwgraph/opengl_svmwgraph.c @@ -1,54 +1,176 @@ /* The OpenGL hooks for the Super VMW graphics library */ +/* based on the "glxheads.c" file from the Mesa 3.4 demos distribution */ + #include -#include #include +#include + #include "svmwgraph.h" #include /* For atexit() */ #include -float palette[256][3]; +static float rotation=0.0; +unsigned char palette[256][4]; + +#define TEXTURE_SIZE 32 + +typedef struct { + GLubyte *texture_data; + GLuint texture_name; + GLfloat x1,y1,x2,y2; +} texture_block; + +texture_block *texture_grid; +texture_block *current_texture; + +GLuint temp_texture_name; +int texnumx,texnumy; + +static Display *display; +static Window win; +static GLXContext ctx; /* Setup the Graphics */ /* Pass '0' to auto-detect bpp */ void *openGL_setupGraphics(int *xsize,int *ysize,int *bpp, - int fullscreen,int verbose) -{ - + int fullscreen,int verbose) { + + int scrnum,x,y; + XSetWindowAttributes attr; + Window root; + XVisualInfo *visinfo; + unsigned long mask; + XSizeHints sizehints; - /* ^^*&^$%*&$^*&%^$ I am too stubborn to pass the real argc and */ - /* argv through.. and I can't get this to work otherwise. */ - /* I am tired of screwing with it though, so this is known broken */ - int argc2=3,i; - char argv2[3][10]; + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + None }; - strcpy(argv2[0],"vmw"); - strcpy(argv2[1],"mlp"); - strcpy(argv2[2],"amg"); - - for(i=0;ivisual,AllocNone); + attr.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask; + mask =CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow(display,root,0,0,640,400, + 0,visinfo->depth,InputOutput,visinfo->visual,mask, + &attr); + if (!win) { + printf("Could not create X-window!\n"); + return NULL; + } + + sizehints.x=10; + sizehints.y=10; + sizehints.width=640; + sizehints.height=400; + sizehints.flags=USSize | USPosition; + XSetNormalHints(display,win,&sizehints); + XSetStandardProperties(display,win,NULL,NULL, + None,(char **)NULL,0,&sizehints); + ctx=glXCreateContext(display,visinfo,NULL,True); + if (ctx==NULL) { + printf("Can't create GLX context!\n"); + return NULL; + } + XMapWindow(display,win); + if (!glXMakeCurrent(display,win,ctx)) { + printf("glXMakeCurrent failed!\n"); + return NULL; + } + + printf(" GL_VERSION: %s\n", glGetString(GL_VERSION)); + printf(" GL_VENDOR: %s\n", glGetString(GL_VENDOR)); + printf(" GL_RENDERER: %s\n", glGetString(GL_RENDERER)); + + glClearColor(0.0,0.0,0.0,0.0); + glShadeModel(GL_FLAT); +// glShadeModel(GL_SMOOTH); +// glEnable(GL_POLYGON_SMOOTH); +// glEnable(GL_BLEND); +// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + glPixelStorei(GL_UNPACK_ALIGNMENT,1); + +// for (i=0;itexture_data=malloc(TEXTURE_SIZE*TEXTURE_SIZE); + + current_texture->x1=x*TEXTURE_SIZE; + current_texture->y1=y*TEXTURE_SIZE; + current_texture->x2=(x+1)*TEXTURE_SIZE; + if (current_texture->x2>320) current_texture->x2=320; + current_texture->y2=(y+1)*TEXTURE_SIZE; + if (current_texture->y2>200) current_texture->y2=200; + + glGenTextures(1,&temp_texture_name); + current_texture->texture_name=temp_texture_name; + + glBindTexture(GL_TEXTURE_2D, temp_texture_name); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,TEXTURE_SIZE, + TEXTURE_SIZE,0,GL_RGBA,GL_UNSIGNED_BYTE, + current_texture->texture_data); +// glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); + + } + } - /* Clean up on exit */ - return (char *)(1); + glOrtho(-20,340,-20,220,-100,100); + +// gluPerspective(60,1.6,-10,10); + + return (char *)(1); } @@ -57,16 +179,90 @@ void openGL_flushPalette(vmwSVMWGraphState *state) { int i; for(i=0;i<256;i++) { - palette[i][0]=((float) ((state->palette[i]>>11)<<3))/256.0; - palette[i][1]=((float) ( ((state->palette[i]>>5)&0x3f)<<2))/256.0; - palette[i][2]=((float) ((state->palette[i]&0x1f)<<3))/256.0; + palette[i][0]=((state->palette[i]>>11)<<3); + palette[i][1]=( ((state->palette[i]>>5)&0x3f)<<2); + palette[i][2]=((state->palette[i]&0x1f)<<3); + palette[i][3]=255; } } void openGL_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { + + int x=0,y=0,temp_col,i,j,ending_j,ending_i; + unsigned char *s_pointer; + + GLubyte *t_pointer; + + if (!glXMakeCurrent(display,win,ctx)) { + printf("Error getting context!\n"); + return; + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushMatrix(); + + glRotatef(rotation,160,100,0); +// glEnable(GL_DEPTH_TEST); + glEnable(GL_TEXTURE_2D); + + for(y=0;ytexture_name); + + s_pointer=source->memory+((y*TEXTURE_SIZE)*320)+(x*TEXTURE_SIZE); + + t_pointer=(current_texture->texture_data); + + ending_j=TEXTURE_SIZE; + if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>200) + ending_j=200%TEXTURE_SIZE; + + ending_i=TEXTURE_SIZE; + if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>320) + ending_i=320%TEXTURE_SIZE; +// printf("==>%i %i %p\n",x,y,current_texture); fflush(stdout); + + + for(j=0;j>>%p %p=%i\n",t_pointer,s_pointer,temp_col); fflush(stdout); + memcpy(t_pointer,palette[temp_col],3); + s_pointer++; + t_pointer+=4; + } + s_pointer+=(320-TEXTURE_SIZE); + } + + glTexSubImage2D(GL_TEXTURE_2D, + 0,0,0,TEXTURE_SIZE,TEXTURE_SIZE, + GL_RGBA, + GL_UNSIGNED_BYTE, + current_texture->texture_data); + + glBegin(GL_QUADS); + glTexCoord2f(0.0,0.0); glVertex3f(current_texture->x1,current_texture->y1,0.0); + glTexCoord2f(1.0,0.0); glVertex3f(current_texture->x2,current_texture->y1,0.0); + glTexCoord2f(1.0,1.0); glVertex3f(current_texture->x2,current_texture->y2,0.0); + glTexCoord2f(0.0,1.0); glVertex3f(current_texture->x1,current_texture->y2,0.0); + glEnd(); + } + + } + glFlush(); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glPopMatrix(); + + glXSwapBuffers(display,win); + + /* int x,y; unsigned char *s_pointer; @@ -81,7 +277,7 @@ void openGL_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { // *((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)]; s_pointer++; } - glFlush(); + */ } void openGL_clearKeyboardBuffer() { @@ -91,7 +287,90 @@ void openGL_clearKeyboardBuffer() { } +void reshape(int w,int h) { + glViewport(0,0,(GLsizei)w,(GLsizei)h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w<=h) + glOrtho(-30,30,-30*(GLfloat)h/(GLfloat)w, + 30*(GLfloat)h/(GLfloat)w,-30,30); + else + glOrtho(-20,340,-20, + 220,-100,100); + + + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + + + int openGL_getInput() { + + static int keydown=0; + KeySym keysym; + XEvent E; + char keyname[18]; + + while (XPending(display) > 0) { + XNextEvent(display, &E); + if (E.xany.window == win) { + switch (E.type) { + case Expose: + //Redraw(); + break; + case ConfigureNotify: + reshape(E.xconfigure.width, E.xconfigure.height); + break; + case KeyPress: + keydown=1; + case KeyRelease: + /* get bare keysym, for the scancode */ + keysym = XLookupKeysym ((XKeyEvent *) &E, 0); + /* get key name, using modifiers for the unicode */ + XLookupString ((XKeyEvent *) &E, keyname, 16, NULL, NULL); + +// fprintf(stderr, "Keyevent keycode: %04X, keysym: %04X, unicode: %02X\n", +// E.xkey.keycode, (unsigned int)keysym, (unsigned int)keyname[0]); + + /* look which table should be used */ +// if ( (keysym & ~0x1ff) == 0xfe00 ) +// event.scancode = extended_code_table[keysym & 0x01ff]; +// else if (keysym < 0xff) +// event.scancode = code_table[keysym & 0x00ff]; +// else +// event.scancode = 0; +// +// event.unicode = keyname[0]; + +// keyboard_register_event(&event); + switch(E.xkey.keycode) { + case 0x09: return VMW_ESCAPE; + case 0x24: return VMW_ENTER; + case 0x62: return VMW_UP; + case 0x68: return VMW_DOWN; + case 0x66: return VMW_RIGHT; + case 0x64: return VMW_LEFT; + case 0x41: return ' '; + case 0x43: return VMW_F1; + case 0x44: return VMW_F2; + case 0x63: return VMW_PGUP; + case 0x69: return VMW_PGDN; + case 0x4A: /* F8 */ + rotation+=10.0; + printf("Rotation now=%f\n",rotation); + return 0; + } + break; + + default: + /*no-op*/ ; + } + } + } + /* SDL_Event event; int keypressed; diff --git a/tb1.c b/tb1.c index 495d092..7c61dc7 100644 --- a/tb1.c +++ b/tb1.c @@ -10,7 +10,7 @@ \* This source is released under the GPL */ /****************************************************************/ -#define TB1_VERSION "2.9.12" +#define TB1_VERSION "2.9.13" #include #include /* for calloc */ @@ -42,6 +42,7 @@ int command_line_help(int show_version,char *runas) printf(" -double : play in 640x480 mode\n"); printf(" -fullscreen : play in fullscreen mode (if available)\n"); printf(" -nosound : disables sound within game\n"); + printf(" -opengl : play in openGL mode\n"); printf(" -version : print version\n"); printf(" -? : print this help message\n"); printf("\n"); @@ -180,6 +181,8 @@ int main(int argc,char **argv) game_state->sound_possible=0; printf(" + Sound totally disabled\n"); break; + case 'o': + graphics_target=VMW_OPENGLTARGET; break; default : command_line_help(0,argv[0]); printf("Unknown Option: %s\n\n",argv[i]); return 5;