void obj_dummy_draw( int objid, OBJ_t *o ) { DUMMY_t *du = o->data; SDL_Rect drect = (SDL_Rect) { du->pos.x +du->hull[0].x, du->pos.y +du->hull[0].y, du->hull[1].x-du->hull[0].x, du->hull[1].y-du->hull[0].y }; Sint16 offs = drect.w==drect.h ? 48 : 0; SJGL_SetTex( sys_tex[TEX_WORLD].num ); if( drect.w > drect.h ) while( drect.w>0 && drect.w<400 ) { SJGL_Blit( &(SDL_Rect) { 0+offs,16,16,16 }, drect.x, drect.y, 0 ); drect.x += 16; drect.w -= 16; offs = drect.w==16 ? 32 : 16; } else while( drect.h>0 && drect.h<400 ) { SJGL_Blit( &(SDL_Rect) { 48,0+offs,16,16 }, drect.x, drect.y, 0 ); drect.y += 16; drect.h -= 16; offs = drect.h==16 ? 32 : 16; } }
void mod_huddraw(unsigned int vidfr) { // draw HUD here! // popups unsigned int vidfrmod = vidfr % maxframes; int i; for( i=0; i<maxobjs; i++ ) { object *ob = fr[vidfrmod].objs+i; if( ob->type != popup_type ) continue; popup *pop = ob->data; if( pop->visible ) { V *pos = flex(ob, pos); V *hull = flex(ob, hull); if( i==gui_hover && pop->enabled ) { SJGL_SetTex( 0 ); SJGL_SetTex( 2 ); // FIXME: NO NO NO! SJGL_Blit( &(REC){30, 30, hull[1].x, hull[1].y}, pos->x, pos->y, 0 ); } drawtext( pos->x, pos->y, FONT_LEFT, "%s", pop->text ); } } }
void mod_outerdraw(unsigned int vidfr, int w, int h) { if( !editmode ) return; glPushAttrib(GL_CURRENT_BIT); int sz = NATIVE_TEX_SZ; glBindTexture(GL_TEXTURE_2D, 0); glColor4f(0.1, 0.1, 0.1, 0.8f ); SJGL_Blit(&(REC){0, 0, sz, sz}, w-sz, 0, 0 ); SJGL_SetTex(mytex); glColor4f(1, 1, 1, 1); SJGL_Blit(&(REC){0, 0, sz, sz}, w-sz, 0, 0); size_t i; glBindTexture(GL_TEXTURE_2D, 0); // draw sprite boxes for( i=0; i<spr_count; i++ ) { if( sprites[i].texnum != mytex ) continue; int b1, b2; if( myspr==(int)i ) { glColor4f(1, 1, 0, 1.0f); b1 = 4; } else { glColor4f(1, 1, 1, 0.6f); b1 = 1; } b2 = b1*2; REC rec = sprites[i].rec; int x = w-sz+rec.x; int y = rec.y; SJGL_Blit( &(REC){0, 0, rec.w+b2, b1}, x- b1, y- b1, 0 ); SJGL_Blit( &(REC){0, 0, rec.w+b2, b1}, x- b1, y+rec.h, 0 ); SJGL_Blit( &(REC){0, 0, b1, rec.h}, x- b1, y , 0 ); SJGL_Blit( &(REC){0, 0, b1, rec.h}, x+rec.w, y , 0 ); } // draw anchor points glColor4f(1, 0, 0, 0.8f); for( i=0; i<spr_count; i++ ) { if( sprites[i].texnum != mytex ) continue; REC rec = sprites[i].rec; int x = w-sz+rec.x; int y = rec.y; if( myspr==(int)i ) SJGL_Blit( &(REC){0,0,4,4}, x+sprites[i].ancx-2, y+sprites[i].ancy-2, 0 ); else SJGL_Blit( &(REC){0,0,2,2}, x+sprites[i].ancx-1, y+sprites[i].ancy-1, 0 ); } glColor4f(1, 1, 1, 1); if( myspr < (int)spr_count ) { drawtext( w-sz, sz+ 4, FONT_LEFT, "Texture #%d \"%s\"", mytex, mytex < (int)tex_count ? textures[mytex].filename : "ERROR! mytex > tex_count" ); drawtext( w-sz, sz+14, FONT_LEFT, "Sprite #%d \"%s\"", myspr, sprites[myspr].name ); drawtext( w-sz, sz+24, FONT_LEFT, "Layer %d", ylayer ); } glPopAttrib(); drawtext(i_mousex+7, i_mousey+15, FONT_LEFT, "%d", ylayer); }
void render() { const SDL_VideoInfo *vidinfo; int x,y,w,h; int i; char buf[1000]; Uint32 vidfr = (metafr-1); Uint32 vidfrmod = vidfr%maxframes; Uint32 render_start = SDL_GetTicks(); static Uint32 total_start = 0; Uint32 tmp; if( metafr==0 || vidfr<=drawnfr ) //==0 prevent never-draw bug return; if( soon==1 ) setvideo(soon_w,soon_h,soon_full,0); if( soon>0 ) soon--; vidinfo = SDL_GetVideoInfo(); w = v_w = vidinfo->current_w; h = v_h = vidinfo->current_h; pad_left = 0; pad_top = 0; if( v_center ) { pad_left = (w - NATIVEW*scale)/2; pad_top = (h - NATIVEH*scale)/2; } glMatrixMode(GL_TEXTURE); glLoadIdentity(); glScalef(1.0f/256.0f, 1.0f/256.0f, 1); glColor4f(1.0f,1.0f,1.0f,1.0f); glEnable(GL_TEXTURE_2D); if( v_usealpha ) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); else glBlendFunc(GL_ONE, GL_ZERO); glEnable(GL_BLEND); glAlphaFunc(GL_GREATER,0.01); glEnable(GL_ALPHA_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glClear(GL_DEPTH_BUFFER_BIT); // viewport and matrixes for game objects glViewport(pad_left,h-NATIVEH*scale-pad_top,NATIVEW*scale,NATIVEH*scale); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,NATIVEW,NATIVEH,0,-NATIVEH*3-1,NATIVEH*3+1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); int camx = NATIVEW/2-(int)v_camx, camy = NATIVEH/2-(int)v_camy; glTranslatef(camx,camy,0); SJGL_SetTex( (GLuint)-1 ); //forget previous texture name mod_predraw(vidfr); //display objects for(i=0;i<maxobjs;i++) { OBJ_t *o = fr[vidfrmod].objs+i; if( o->flags&OBJF_VIS ) mod_draw(i,o); // have the mod draw the actual thing } mod_postdraw(vidfr); glDisable(GL_DEPTH_TEST); //display hulls and object numbers if( v_drawhulls ) { glBindTexture( GL_TEXTURE_2D, 0 ); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); if( mycontext ) { CONTEXT_t *co = fr[vidfrmod].objs[mycontext].data; int x,y,z; for( z=0; z<co->z; z++ ) for( y=0; y<co->y; y++ ) for( x=0; x<co->x; x++ ) { int pos = co->x*co->y*z + co->x*y + x; int flags; if( co->dmap[ pos ].flags & CBF_NULL ) flags = co->map[ pos ].flags; else flags = co->dmap[ pos ].flags; if( flags & CBF_SOLID ) { glColor4f(1,0,0,1); SJGL_Blit( &(SDL_Rect){0,0,16,16}, x*16, y*16, z ); SJGL_Blit( &(SDL_Rect){0,0,12,12}, x*16+2, y*16+2, z ); } else if( flags & CBF_PLAT ) { glColor4f(0,1,0,1); SJGL_Blit( &(SDL_Rect){0,0,16, 2}, x*16, y*16, z ); } } } glColor4f(1,1,1,1); for(i=0;i<maxobjs;i++) { OBJ_t *o = fr[vidfrmod].objs+i; V *pos = flex(o,OBJF_POS); V *hull = flex(o,OBJF_HULL); if( pos && hull ) { SDL_Rect rect = (SDL_Rect){0, 0, hull[1].x-hull[0].x, hull[1].y-hull[0].y}; SJGL_Blit( &rect, pos->x+hull[0].x, pos->y+hull[0].y, 0 ); } } glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); for(i=0;i<maxobjs;i++) { OBJ_t *o = fr[vidfrmod].objs+i; V *pos = flex(o,OBJF_POS); if( pos ) { sprintf(buf,"%d",i); SJF_DrawText(pos->x, pos->y, buf); } } } // viewport and matrixes for HUD glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,w,h,0,-1,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //paint black over the border areas, subtractively with v_oob { int outerl = 0; int innerl = pad_left; int outert = 0; int innert = pad_top; int outerr = w; int innerr = pad_left + NATIVEW*scale; int outerb = h; int innerb = pad_top + NATIVEH*scale; glDisable(GL_TEXTURE_2D); glPushAttrib(GL_COLOR_BUFFER_BIT); if( v_oob ) { glColor4f(0.02,0.02,0.02,0.02); glBlendFunc(GL_ONE,GL_ONE); if( GLEW_EXT_blend_equation_separate ) glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); } else glColor4f(0,0,0,1.0f); glBegin(GL_QUADS); glVertex2i(outerl,outert); glVertex2i(outerr,outert); glVertex2i(outerr,innert); glVertex2i(outerl,innert); //top glVertex2i(outerl,innerb); glVertex2i(outerr,innerb); glVertex2i(outerr,outerb); glVertex2i(outerl,outerb); //bottom glVertex2i(outerl,innert); glVertex2i(innerl,innert); glVertex2i(innerl,innerb); glVertex2i(outerl,innerb); //left glVertex2i(innerr,innert); glVertex2i(outerr,innert); glVertex2i(outerr,innerb); glVertex2i(innerr,innerb); //right glEnd(); glPopAttrib(); glEnable(GL_TEXTURE_2D); glColor4f(1.0f,1.0f,1.0f,1.0f); } SJGL_SetTex( (GLuint)-1 ); //forget previous texture name mod_outerdraw(vidfr,w,h); //display console if(console_open) { int conh = h/2 - 40; if(conh<40) conh = 40; glColor4f(0.15,0.15,0.15,0.85); glDisable(GL_TEXTURE_2D); glBegin(GL_QUADS); glVertex2i(0, 0); glVertex2i(w, 0); glVertex2i(w,conh); glVertex2i(0,conh); glEnd(); glEnable(GL_TEXTURE_2D); glColor4f(1.0f,1.0f,1.0f,1.0f); x = 10; y = conh-20; if((ticks/200)%2) SJF_DrawChar(x+SJF_TextExtents(SJC.buf[0]), y, '_'); for(i=0;y>0;i++) { if(SJC.buf[i]) SJF_DrawText(x,y,SJC.buf[i]); y -= 10; } if( SJC.buf[0] && SJC.buf[0][0] ) { char s[10]; sprintf(s,"%d",SJC.buf[0][strlen(SJC.buf[0])-1]); SJF_DrawText(w-20,conh-20,s); } } //display stats total_time += (tmp = SDL_GetTicks()) - total_start; render_time += tmp - render_start; total_start = tmp; Uint32 unaccounted_time = total_time - (idle_time + render_time + adv_move_time + adv_collide_time + adv_game_time); if( v_showstats ) { Uint32 denom = vidfrmod+1; sprintf(buf,"idle_time %4d" , idle_time/denom); SJF_DrawText(w-20-SJF_TextExtents(buf),10,buf); sprintf(buf,"render_time %4d" , render_time/denom); SJF_DrawText(w-20-SJF_TextExtents(buf),20,buf); sprintf(buf,"adv_move_time %4d" , adv_move_time/denom); SJF_DrawText(w-20-SJF_TextExtents(buf),30,buf); sprintf(buf,"adv_collide_time %4d",adv_collide_time/denom); SJF_DrawText(w-20-SJF_TextExtents(buf),40,buf); sprintf(buf,"adv_game_time %4d" , adv_game_time/denom); SJF_DrawText(w-20-SJF_TextExtents(buf),50,buf); sprintf(buf,"unaccounted_time %4d",unaccounted_time/denom); SJF_DrawText(w-20-SJF_TextExtents(buf),60,buf); sprintf(buf,"adv_frames %2.2f" ,(float)adv_frames/(float)denom); SJF_DrawText(w-20-SJF_TextExtents(buf),70,buf); sprintf(buf,"fr: idx=%d meta=%d vid=%d hot=%d",metafr%maxframes,metafr,vidfr,hotfr); SJF_DrawText(w-20-SJF_TextExtents(buf),80,buf); } SDL_GL_SwapBuffers(); setdrawnfr(vidfr); if( (int)vidfrmod==maxframes-1 ) { // reset time stats total_time = 0; idle_time = 0; render_time = 0; adv_move_time = 0; adv_collide_time = 0; adv_game_time = 0; adv_frames = 0; } }