void glk_make_sdl_window(void) { s=initsdl(w,h,&bpp,SDL_OPENGL); SDL_EnableUNICODE(1); SDL_InitSubSystem( SDL_INIT_TIMER); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY/2, SDL_DEFAULT_REPEAT_INTERVAL/3); gle(); resetviewport(); resetmatrices(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glClearColor( 0.0, 0.0, 0.0, 0.0 ); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); printf("LEMON\n"); }
int RunGLTest () { int bpp; int w = 500; int h = 500; int done = 0; int shrink=0; int grow=0; xy s = parsemodes(w,h,"mode",1,0,0); if (s.x!=-1){w=s.x;h=s.y;}; Uint32 video_flags=initsdl(w,h,&bpp); /* Set the window manager title bar */ SDL_WM_SetCaption( "SDL GL test", "testgl" ); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); wm(w,h); glDepthFunc(GL_LESS); glEnable(GL_BLEND); glShadeModel(GL_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE); add_terminal(); glLineWidth(1); glClearColor( 0.0, 0.0, 0.0, 1.0 ); while( !done ) { GLenum gl_error; char* sdl_error; SDL_Event event; glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); rote_vt_update(t); glPushMatrix(); glRotatef(rot,1,0,0); glPushMatrix(); glTranslatef(-2.52,1.92,0); glPushMatrix(); activetext=(active==2); if (active==2) glScalef(0.003,-0.003,1); else glScalef(0.002,-0.002,1); draw_terminal(t); glPopMatrix(); glPushMatrix(); activetext=(active==1); if (active==1) glScalef(0.003,-0.003,1); else glScalef(0.002,-0.002,1); glTranslatef(0,plscroll*60,0); PyRun_SimpleString("dr_aw()"); glPopMatrix(); glPopMatrix(); glPopMatrix(); SDL_GL_SwapBuffers( ); gl_error = glGetError( ); if( gl_error != GL_NO_ERROR ) fprintf( stderr, "testgl: OpenGL error: %d\n", gl_error ); sdl_error = SDL_GetError( ); if( sdl_error[0] != '\0' ) { fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error); SDL_ClearError(); } { } /* Check if there's a pending event. */ while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: printf("%i\n",event.key.keysym.unicode); int key=event.key.keysym.sym; if ( key==SDLK_UP ) { PyRun_SimpleString("pl_up()"); active=1; } if ( key==(SDLK_DOWN) ) { PyRun_SimpleString("pl_down()"); active=1; } if ( key==(SDLK_PAGEUP) ) { PyRun_SimpleString("pl_pgup()"); active=1; } if ( key==(SDLK_PAGEDOWN) ) { PyRun_SimpleString("pl_pgdown()"); active=1; } else if ( (key == SDLK_SPACE) ) keyp(32); else if ( (key == SDLK_q) ) rot++; else if ( (key == SDLK_w) ) rot--; else if ( (key == SDLK_e) ) glLineWidth(3); else if ( (key == SDLK_r) ) glLineWidth(4); else if ( (key == SDLK_t) ) glLineWidth(5); else if ( (key == SDLK_y) ) glLineWidth(6); else if ( (key == SDLK_F1) ) shrink=1; else if ( (key == SDLK_F2) ) grow=1; else if ( (key == SDLK_END) ) { PyRun_SimpleString("pl_end()"); active=1; } else if ( (key == SDLK_HOME) ) { PyRun_SimpleString("pl_home()"); active=1; } else if ( (key == SDLK_q) ) { PyRun_SimpleString("wanna_play()"); wannaplay=1; active=2; } else if ( (key == SDLK_RETURN) ) { keyp(10); PyRun_SimpleString("wanna_play()"); wannaplay=1; active=2; } else if ( (key == SDLK_c) ) done=1; break; case SDL_QUIT: done = 1; break; } } if (wannaplay) { FILE *f; if (f=fopen("/tmp/sftkoko","r")) fclose(f); else { wannaplay=0; PyRun_SimpleString("pl_ay()"); } } if (shrink||grow) resize(&w,&h,&bpp,&video_flags,&shrink,&grow); } SDL_Quit( ); return(0); }
int RunGLTest (void) { #ifdef GL int mm=1; #else int mm = 0; #endif int mode=0; cam.x=0; cam.y=0; int bpp; int w = 200; int h = 200; int done = 0; int shrink=0; int grow=0; int gofullscreen=0; int mustresize = 1; int justresized = 0; xy ss = parsemodes(w,h,"mode",1,0,0); printf("wtf\n"); if (ss.x!=-1){w=ss.x;h=ss.y;}; SDL_Surface* s; #ifdef GL s=initsdl(w,h,&bpp,SDL_OPENGL #else gltextsdlsurface=s=initsdl(w,h,&bpp, #endif +0);printf("inito\n"); SDL_InitSubSystem( SDL_INIT_TIMER); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY/2, SDL_DEFAULT_REPEAT_INTERVAL*2); #ifdef GL newtermmsg=GetFileIntoCharPointer1("newtermmsg"); printf("pretty far\n"); wm(w,h); int down=0; glEnable(GL_BLEND); glShadeModel(GL_FLAT); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glClearColor( 0.0, 0.0, 0.04, 0.0 ); glLineWidth(lv); #else gltextsdlsurface=s; #endif roteface *face1; roteface *activeface; face1=add_face(); activeface =face1 ; face1->next=add_face(); printf("still?\n"); add_terminal(face1); printf("2threaad\n"); loadl2(); struct state *nerv=0; #ifdef nerve nerv=nerverot_init(w,h); #endif int dirty=1; printf("mainloop descent commencing\n"); while( !done ) { lockterms(face1); if(dirty||faces_dirty(face1)) { dirty=0; facesclean(face1); #ifdef GL glClear(GL_COLOR_BUFFER_BIT); #else SDL_FillRect ( s, NULL, 0 ); #endif #ifndef GL #else if(nerv) { shownerv(nerv); dirty=1; } glPushMatrix(); glScalef(sx,sy,0.004); glTranslatef(cam.x,cam.y,0); #endif Uint8 * k; int integer; k=SDL_GetKeyState(&integer); if(k[SDLK_RCTRL]) focusline(activeface); int nf; switch(mode) { case 0: showfaces(face1); break; #ifdef GL case 1: krychlus(face1); break; #endif } #ifdef GL glPopMatrix(); #endif #ifndef GL SDL_UpdateRect(s,0,0,0,0); #else SDL_GL_SwapBuffers( ); #endif facesclean(face1); } #ifdef GL GLenum gl_error; gl_error = glGetError( ); if( gl_error != GL_NO_ERROR ) { if(gl_error==GL_STACK_OVERFLOW) printf("QUACK QUACK QUACK, OVERFLOVING STACK\n"); else if(gl_error==GL_INVALID_OPERATION) printf("INVALID OPERATION, PATIENT EXPLODED\n"); else fprintf( stderr, "testgl: OpenGL error: %d\n", gl_error ); } #endif char* sdl_error; sdl_error = SDL_GetError( ); if( sdl_error[0] != '\0' ) { fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error); SDL_ClearError(); } SDL_TimerID x=0; if(dirty) x= SDL_AddTimer(55, NewTimerCallback, 0); unlockterms(face1); // printf("---------unlocked wating\n"); SDL_Event event; if(SDL_WaitEvent( &event )) { lockterms(face1); // printf("---------locked goooin %i\n", event.type); if(x)SDL_RemoveTimer(x);x=0; do { int mod=event.key.keysym.mod; int key=event.key.keysym.sym; Uint8 *keystate = SDL_GetKeyState(NULL); switch( event.type ) { #ifdef GL case SDL_MOUSEMOTION: if((SDL_BUTTON(1)|SDL_BUTTON(2))&SDL_GetMouseState(0,0)) { activeface->x+=event.motion.xrel; activeface->y+=event.motion.yrel; } if((SDL_BUTTON(3)|SDL_BUTTON(2))&SDL_GetMouseState(0,0)) { cam.x-=event.motion.xrel; cam.y-=event.motion.yrel; } break; #endif case SDL_KEYUP: { if ( (key == SDLK_RCTRL) ) { dirty=1; } } break; case SDL_KEYDOWN: if(mod&KMOD_RSHIFT&&(key==SDLK_PAGEUP||key==SDLK_PAGEDOWN)) { if(key==SDLK_PAGEUP) tscroll+=9; if(key==SDLK_PAGEDOWN) tscroll-=9; if(tscroll<0)tscroll=0; // printf("scroll:%i,logl:%i, log&%i, t:%i ,b:%i\n", tscroll,activeface->t->logl, activeface->t->log,activeface->t->scrolltop,activeface->t->scrollbottom); } else if(key==SDLK_RCTRL||mod&KMOD_RCTRL) { dirty=1; switch (key) { case SDLK_TAB: cycle(face1, &activeface); break; case SDLK_F2: gofullscreen=1; break; case SDLK_F3: rastio+=0.05; mustresize=1; dirty=1; break; case SDLK_F4: rastio-=0.05; mustresize=1; dirty=1; break; case SDLK_F5: sx-=0.001; sy+=0.001; break; case SDLK_F6: sx+=0.001; sy-=0.001; break; case SDLK_F7: savemode(w,h); break; case SDLK_F8: loadl2(); break; case SDLK_p: saveScreenshot(); break; #ifdef GL case SDLK_F9: lv-=1; glLineWidth(lv); break; case SDLK_F10: lv+=1; glLineWidth(lv); break; #endif case SDLK_F11: shrink=1; break; case SDLK_F12: grow=1; break; case SDLK_PAGEUP: mode++; if(mode>mm)mode= mm; break; case SDLK_INSERT: mode--; if(mode<0)mode= 0; break; case SDLK_END: resizooo(activeface, 0,1,keystate); break; case SDLK_HOME: resizooo(activeface, 0,-1,keystate); break; case SDLK_DELETE: resizooo(activeface, -1,0,keystate); break; case SDLK_PAGEDOWN: resizooo(activeface, 1,0,keystate); break; #ifdef nerve case SDLK_F1: if(nerv) { nerverot_free(nerv); dirty=1; nerv=0; } else { nerv=nerverot_init(w,h); dirty=1; } break; #endif } } else { if(activeface->t==0) { printf("debug messages r fun\n"); add_terminal(activeface); activeface->next=add_face(); } if ( (key >= SDLK_F1) && (key <= SDLK_F15) ) { char *k; if(asprintf(&k ,"kf%i", key-SDLK_F1+1)!=-1) { rote_vt_terminfo(activeface->t, k); free(k); } } else if ( (key == SDLK_SPACE) ) keyp(activeface,32); else #define magic(x) rote_vt_terminfo(activeface->t, x ) if ( (key == SDLK_BACKSPACE) ) magic( "kbs"); else if ( (key == SDLK_ESCAPE) ) keyp(activeface,27); else if ( (key == SDLK_LEFT) ) magic("kcub1"); else if ( (key == SDLK_RIGHT) ) magic( "kcuf1"); else if ( (key == SDLK_UP) ) magic( "kcuu1"); else if ( (key == SDLK_DOWN) ) magic( "kcud1"); else if ( (key == SDLK_END) ) magic( "kend"); else if ( (key == SDLK_HOME) ) magic("khome"); else if ( (key == SDLK_DELETE) ) magic( "kdch1"); else if ( (key == SDLK_PAGEDOWN) ) magic( "knp"); else if ( (key == SDLK_INSERT) ) magic( "kich1"); else if ( (key == SDLK_PAGEUP) ) magic ( "kpp" ); else if ( (key == SDLK_RETURN) ) keyp(activeface,10); else if( event.key.keysym.unicode && ( (event.key.keysym.unicode & 0xFF80) == 0 ) ) keyp(activeface, event.key.keysym.unicode); } break; case SDL_QUIT: done = 1; break; #ifndef GL case SDL_MOUSEBUTTONDOWN: rote_vt_mousedown(activeface->t,event.button.x/13, event.button.y/26); break; case SDL_MOUSEBUTTONUP: rote_vt_mouseup (activeface->t,event.button.x/13, event.button.y/26); break; case SDL_MOUSEMOTION: rote_vt_mousemove(activeface->t,event.button.x/13, event.button.y/26); break; #endif case SDL_VIDEORESIZE: { w=event.resize.w;h=event.resize.h; // printf("videoresize %i %i\n", w,h); dirty=1; if (s=SDL_SetVideoMode( w,h, bpp, s->flags ) ) // printf("hmm\n"); wm(w,h); if(!justresized) mustresize=1; justresized=0; } break; case SDL_USEREVENT: if(event.user.code==1) RemoveTerm(&activeface,&face1, event.user.data1); break; } } while (SDL_PollEvent(&event)); if (shrink||grow) { resize(&w,&h,&bpp,&s->flags,&shrink,&grow); wm(w,h); } if (mustresize) { mustresize=0; justresized=1; // if(activeface->t->cols!=event.resize.w/13/rastio|| // activeface->t->rows!=event.resize.h/26/rastio) //rote_vt_resize(activeface->t,event.resize.h/26/rastio ,event.resize.w/13/rastio); } if(gofullscreen) if(s->flags & SDL_FULLSCREEN ) { s=SDL_SetVideoMode( w,h, bpp, (s->flags & ~SDL_FULLSCREEN )); } else s=SDL_SetVideoMode( w,h, bpp, (s->flags | SDL_FULLSCREEN )); gofullscreen=0; unlockterms(face1); } } SDL_Quit( ); return(0); }
int main(int argc, char *argv[]) { int mode = SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | SDL_OPENGL; if (argc >= 2 && (! strcmp(argv[1], "-h") || ! strcmp(argv[1], "--help"))) { printf("Uso: %s [-fs] resolucao-x resolucao-y\n\n" "Exemplo: ./walker 1024 768\n\n" "Para mais informacoes, leia o README.\n", argv[0]); exit(0); } int shift = 1; if (argc >= 2 && ! strcmp(argv[1], "-fs")) { mode |= SDL_FULLSCREEN; res_x = 1360; res_y = 768; shift++; } if (argc >= 3) { res_x = atoi(argv[shift]); res_y = atoi(argv[shift+1]); } init_event_keys(); glutInit(&argc, argv); initsdl(mode); initgl(); carregar_texturas(); SDL_Event ev; while (1) if (! SDL_PollEvent(&ev) || ev.type == SDL_MOUSEMOTION) break; else event_handler(ev); uint64_t old_time, new_time; uint64_t old_border, new_border; old_time = time_get(); old_border = time_in_secs(old_time); float dt = 0; int count = 0; while (1) { while (SDL_PollEvent(&ev)) event_handler(ev); new_time = time_get(); new_border = time_in_secs(new_time); dt = time_diff(new_time, old_time); if (new_border > old_border) { update_fps_str(count); old_border = new_border; count = 0; } old_time = new_time; count++; update_status_str(); toggle(); model(dt); physics(dt); update_map_pos(); draw(); } }