void DrawMsg(char Msg[]){ boxRGBA(screen,350,400,439,409,16,16,16,0xFF); rectangleRGBA(screen,350,400,439,409,32,32,32,0xFF); if (Msg[strlen(Msg)-1]!='!') stringRGBA(screen,351,401,Msg,200,200,200,0xFF); else stringRGBA(screen,351,401,Msg,250,50,50,0xFF); SDL_UpdateRect(screen,350,400,90,10); }
void SelectBgImg(void){ FILE *F; SDL_Surface *Img; SDL_Rect Rct; char Fls[256][256]; int I,J,C=1,Akt=0; Fls[0][0]='\0'; F=fopen("./bgimages.txt","r"); while ((!feof(F))&&(fgets(Fls[C],255,F)!=NULL)){ while ((strlen(Fls[C]))&&(Fls[C][strlen(Fls[C])-1]<' ')) Fls[C][strlen(Fls[C])-1]='\0'; if (Fls[C][0]!='\0'){ // fprintf(stdout,">%s\n",Fls[C]); if (!strcmp(Fls[C],Lvl[Level].BgFile)) Akt=C; C++; } } fclose(F); while ((!Fire)&&(!Quit)){ strcpy(Lvl[Level].BgFile,Fls[Akt]); Img=IMG_Load(Lvl[Level].BgFile); if (Img!=NULL){ Rct.w=Img->w; Rct.h=Img->h; for (I=0;I<400;I+=Rct.w) for (J=0;J<400;J+=Rct.h){ Rct.x=I; Rct.y=J; SDL_BlitSurface(Img,NULL,Lvl[Level].Bg,&Rct); } SDL_FreeSurface(Img); }else boxRGBA(Lvl[Level].Bg,0,0,399,399,0x40,0x40,0x40,0xFF); DrawGame(); boxRGBA(screen,0,0,200,200,32,32,32,0xFF); boxRGBA(screen,0,100,200,110,64,64,64,0xFF); stringRGBA(screen,1,1,"Select BgImage:",255,255,255,0xFF); for (I=0;I<19;I++) if ((Akt-9+I>=0)&&(Akt-9+I<C)) stringRGBA(screen,1,10+I*10,Fls[Akt-9+I],200,200,200,0xFF); SDL_UpdateRect(screen,0,0,200,200); while ((Fire)||(Up)||(Down)) SDL_PollEvent(&event); while ((!Fire)&&(!Up)&&(!Down)&&(!Quit)) SDL_PollEvent(&event); if ((Up)&&(Akt>0)) Akt--; if ((Down)&&(Akt<C-1)) Akt++; } DrawGame(); }
void drawNameNode(Node* node){ if(node->name != NULL){ float coordxf = miseAEchelleX(node->c->x ,map->bounds->max->x,windows_Width); float coordyf = miseAEchelleY(node->c->y ,map->bounds->max->y,windows_Height); stringRGBA(renderer,coordxf,coordyf,node->name,0,0,0,255); } }
void Texto(int x, int y, const char *c, unsigned char r, unsigned char g, unsigned char b, GRF_Imagen img) { GRF_Imagen ptr = ((img==0) ? ventana : img); stringRGBA(ptr, x, y, c, r, g, b, 255); if (img==0 && dibujo_activo) SDL_UpdateRect(ptr, 0, 0, 0, 0); }
void AccuracyTest2(SDL_Surface *screen, SDL_Surface *picture) { SDL_Surface *zoomed1, *zoomed2, *zoomed3, *zoomed4; int factor; int neww, newh; SDL_Rect target; printf("%s\n", messageText); for (factor = 2; factor < 64; factor += 1) { HandleEvent(); ClearScreen(screen); stringRGBA(screen, 8, 8, messageText, 255, 255, 255, 255); neww = picture->w * factor; newh = picture->h * factor; printf (" zoom %ix%i to %ix%i\n", picture->w, picture->h, neww, newh); zoomed1 = zoomSurface(picture, (float)factor, (float)factor, 0); zoomed2 = zoomSurface(picture, (float)factor, (float)factor, 1); zoomed3 = zoomSurface(picture, (float)factor, -(float)factor, 1); zoomed4 = zoomSurface(picture, -(float)factor, (float)factor, 1); target.x = screen->w/2 - zoomed1->w; target.y = screen->h/2 - zoomed1->h; target.w = zoomed1->w; target.h = zoomed1->h; SDL_BlitSurface(zoomed1, 0, screen, &target); target.x = screen->w/2; target.y = screen->h/2; SDL_BlitSurface(zoomed2, 0, screen, &target); target.x = screen->w/2 - zoomed3->w; target.y = screen->h/2; SDL_BlitSurface(zoomed4, 0, screen, &target); target.x = screen->w/2; target.y = screen->h/2 - zoomed4->h; SDL_BlitSurface(zoomed3, 0, screen, &target); SDL_FreeSurface(zoomed1); SDL_FreeSurface(zoomed2); SDL_FreeSurface(zoomed3); SDL_FreeSurface(zoomed4); /* Display by flipping screens */ SDL_Flip(screen); /* Always delay */ SDL_Delay(250); /* Maybe add extra delay */ if (delay>0) { SDL_Delay(delay); } } SDL_Delay(1000); }
void DrawMessages(void){ char Str[55],I; boxRGBA(screen,0,0,399,100,100,100,100,255); for (I=0;I<10;I++){ sprintf(Str,"%d:%s",I,Lvl[Level].Text[I]); stringRGBA(screen,0,I*10,Str,200,200,200,255); } SDL_UpdateRect(screen,0,0,400,100); }
void Draw(SDL_Renderer *renderer, FPSmanager *fpsm) { int newRate; int currentRate; /* FPSmanager: get current rate */ currentRate = SDL_getFramerate(fpsm); /* Set/switch framerate */ timeout--; if (timeout < 0) { /* New rate */ newRate = 5 + 5 * (rand() % 10); /* Update timeout */ timeout = 2 * newRate; /* New Color */ r = rand() & 255; g = rand() & 255; b = rand() & 255; /* FPSmanager: set new rate */ SDL_setFramerate(fpsm, newRate); } /* Black screen */ ClearScreen(renderer); /* Move */ x += dx; y += dy; /* Reflect */ if ((x<0) || (x>WIDTH)) { dx=-dx; } if ((y<0) || (y>HEIGHT)) { dy=-dy; } /* Draw */ filledCircleRGBA (renderer,x,y,30,r,g,b,255); circleRGBA(renderer,x,y,30,255,255,255,255); /* Report set rate and current delay (from last iteration) */ if (time_passed > 0) { SDL_snprintf(messageText, 1024, "Set rate: %4iHz Last delay=%4ims / Calc.Rate=%4iHz", currentRate, time_passed, 1000 / time_passed); stringRGBA (renderer, WIDTH/2 - 4*strlen(messageText),HEIGHT-24,messageText,255,255,255,255); } /* Simulate some random delay from drawing, business logic, network interaction, etc. */ SDL_Delay(1 + rand() % 10); /* Display */ SDL_RenderPresent(renderer); /* FPSmanager: Delay to a fixed rate */ time_passed = SDL_framerateDelay(fpsm); }
void DrawTxtMenu(char Mnu[10][20]){ int I,L=0; boxRGBA(screen,0,400,419,409,64,64,64,0xFF); rectangleRGBA(screen,0,400,419,409,32,32,32,0xFF); for (I=0;(I<10)&&(Mnu[I][0]!='\0');I++){ stringRGBA(screen,2+L*8,402,Mnu[I],250,250,250,0xFF); L+=strlen(Mnu[I]); } SDL_UpdateRect(screen,0,400,400,10); }
char GetString(char *Dest,int MaxLen,int X, int Y){ int P=strlen(Dest); char *Bck; Bck=(char *)malloc(strlen(Dest)+1); strcpy(Bck,Dest); do{ boxRGBA(screen,X,Y,X+((MaxLen<50)?MaxLen:50)*8,Y+10,100,55,55,255); if (strlen(Dest)<=50) stringRGBA(screen,X+1,Y+1,Dest,250,250,250,255); else stringRGBA(screen,X+1,Y+1,Dest+(strlen(Dest)-50),250,250,250,255); SDL_UpdateRect(screen,X,Y,((MaxLen<50)?MaxLen:50)*8,10); UC=0; do {SDL_PollEvent(&event);} while (!UC); // fprintf(stdout,"'%c'\n",Key); if (UC==8){ if (P>0){ P--; Dest[P]='\0'; } } else if ((!Fire)&&(!Quit)&&(P<MaxLen)){ Dest[P]=UC; P++; Dest[P]='\0'; } }while ((!Fire)&&(!Quit)&&(UC!=13)); if (Quit){ strcpy(Dest,Bck); free(Bck); return 0; } free(Bck); return 1; }
CAMLprim value ml_stringRGBA(value dst,value p,value ch,value col,value alpha) { SDL_Surface *sur= SDL_SURFACE(dst); SDL_Rect rect; SDL_Color c; int r; SDLRect_of_value(&rect,p); SDLColor_of_value(&c,col); r=stringRGBA(sur,rect.x,rect.y,String_val(ch),c.r,c.g,c.b,Int_val(alpha)); return Val_bool(r); }
void DrawGame(void){ int I,J; char Str[20]; SDL_Rect Rct; SDL_BlitSurface(Lvl[Level].Bg,NULL,screen,NULL); for (I=0;I<20;I++) for (J=0;J<20;J++) DrawSpr(Spr[Lvl[Level].M[I][J].BSpr].img,screen,I*20+Lvl[Level].M[I][J].x,J*20+Lvl[Level].M[I][J].y); if (Shades){ // ClearSurface(Sh); boxRGBA(Sh,0,0,399,14,0,0,0,0xFF); boxRGBA(Sh,0,15,14,399,0,0,0,0xFF); boxRGBA(Sh,15,15,399,399,255,0,255,0xFF); for (I=0;I<20;I++) for (J=0;J<20;J++) DrawSpr(Spr[Lvl[Level].M[I][J].FSpr].sha,Sh,I*20+Lvl[Level].M[I][J].x,J*20+Lvl[Level].M[I][J].y); SDL_BlitSurface(Sh,NULL,screen,NULL); } for (I=0;I<20;I++) for (J=0;J<20;J++){ DrawSpr(Spr[Lvl[Level].M[I][J].FSpr].img,screen,I*20+Lvl[Level].M[I][J].x,J*20+Lvl[Level].M[I][J].y); if (Lvl[Level].M[I][J].txt>=0){ sprintf(Str,"T%c",'0'+Lvl[Level].M[I][J].txt); stringRGBA(screen,I*20+2,J*20+6,Str,0xE0,0xE0,0xE0,150); } } // Stat: Level--- DrawSpr(SLevel,screen,1,400-16); R_Blit(SNumbers,screen,(Level/10)*11,0,11,15,15,400-16); R_Blit(SNumbers,screen,(Level%10)*11,0,11,15,26,400-16); // Stat: DeadLine--- if (Lvl[Level].DL){ DrawSpr(STime,screen,200-23,400-17); R_Blit(SNumbers,screen,(Lvl[Level].DL/100)*11,0,11,15,200-9,400-16); R_Blit(SNumbers,screen,((Lvl[Level].DL%100)/10)*11,0,11,15,200+2,400-16); R_Blit(SNumbers,screen,(Lvl[Level].DL%10)*11,0,11,15,200+13,400-16); } SDL_UpdateRect(screen,0,0,400,400); }
void ZoomPicture (SDL_Surface *screen, SDL_Surface *picture, int smooth) { SDL_Surface *rotozoom_picture; SDL_Rect dest; int framecount, framemax, frameinc; double zoomxf,zoomyf; fprintf(stderr, "%s\n", messageText); /* Zoom and display the picture */ framemax=4*360; frameinc=1; for (framecount=360; framecount<framemax; framecount += frameinc) { if ((framecount % 360)==0) frameinc++; HandleEvent(); ClearScreen(screen); zoomxf=(float)framecount/(float)framemax; zoomxf=1.5*zoomxf*zoomxf; zoomyf=0.5+fabs(1.0*sin((double)framecount/80.0)); if ((framecount % 120)==0) { printf (" Frame: %i Zoom: x=%.2f y=%.2f\n",framecount,zoomxf,zoomyf); } if ((rotozoom_picture=zoomSurface (picture, zoomxf, zoomyf, smooth))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); break; } SDL_FreeSurface(rotozoom_picture); } stringRGBA(screen, 8, 8, messageText, 255, 255, 255, 255); /* Display by flipping screens */ SDL_Flip(screen); /* Maybe delay */ if (delay>0) { SDL_Delay(delay); } } /* Pause for a sec */ SDL_Delay(1000); }
void RotatePicture90Degrees (SDL_Surface *screen, SDL_Surface *picture) { SDL_Surface *rotozoom_picture; SDL_Rect dest; int framecount, framemax, frameinc; int numClockwiseTurns; fprintf(stderr, "%s\n", messageText); /* Rotate and display the picture */ framemax = 21; frameinc = 1; numClockwiseTurns = -4; for (framecount=0; framecount<framemax; framecount += frameinc) { HandleEvent(); ClearScreen(screen); printf (" Frame: %i Rotate90: %i clockwise turns\n",framecount,numClockwiseTurns+4); if ((rotozoom_picture=rotateSurface90Degrees(picture, numClockwiseTurns))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); break; } SDL_FreeSurface(rotozoom_picture); } stringRGBA(screen, 8, 8, messageText, 255, 255, 255, 255); /* Display by flipping screens */ SDL_Flip(screen); /* Always delay */ SDL_Delay(333); if (delay>0) { SDL_Delay(delay); } numClockwiseTurns++; } /* Pause for a sec */ SDL_Delay(1000); }
void nameHighway(Way * way,ListNode * l){ if(way->name != NULL){ Node * firstNode = searchNode(map->avl,l->firstRef->nd); Node * lastNode = searchNode(map->avl,l->lastRef->nd); float coordxf = miseAEchelleX(firstNode->c->x ,map->bounds->max->x,windows_Width); float coordyf = miseAEchelleY(firstNode->c->y ,map->bounds->max->y,windows_Height); float coordxl = miseAEchelleX(lastNode->c->x,map->bounds->max->x,windows_Width); float coordyl = miseAEchelleY(lastNode->c->y,map->bounds->max->y,windows_Height); coordxf = rightCoordValue(coordxf,windows_Width); coordxl = rightCoordValue(coordxl,windows_Width); coordyf = rightCoordValue(coordyf,windows_Height); coordyl = rightCoordValue(coordyl,windows_Height); float cx = (coordxf+coordxl) / 2; float cy = (coordyf+coordyl) / 2; stringRGBA(renderer,fabs(cx),fabs(cy),way->name,0,0,0,255); } }
void DrawMenu(T_E_Sel Mnu){ int I; boxRGBA(screen,Mnu.X,0,Mnu.X+19,399,64,64,64,0xFF); boxRGBA(screen,Mnu.X+19,0,Mnu.X+19,399,32,32,32,0xFF); rectangleRGBA(screen,Mnu.X,0,Mnu.X+19,19,32,32,32,0xFF); lineRGBA(screen,Mnu.X+5,5,Mnu.X+10,0,200,200,200,0xFF); lineRGBA(screen,Mnu.X+10,0,Mnu.X+15,5,200,200,200,0xFF); stringRGBA(screen,Mnu.X+1,10,Mnu.Name,200,200,200,0xFF); rectangleRGBA(screen,Mnu.X,380,Mnu.X+19,399,32,32,32,0xFF); lineRGBA(screen,Mnu.X+5,395,Mnu.X+10,399,200,200,200,0xFF); lineRGBA(screen,Mnu.X+10,399,Mnu.X+15,395,200,200,200,0xFF); for (I=0;(I<18)&&(Mnu.Top+I<Mnu.L);I++) DrawSpr(Spr[Mnu.E[Mnu.Top+I].Spr].img,screen,Mnu.X,20+I*20); if ((Mnu.Akt>=Mnu.Top)&&(Mnu.Akt<Mnu.Top+18)){ rectangleRGBA(screen,Mnu.X+1,21+(Mnu.Akt-Mnu.Top)*20,Mnu.X+18,19+(Mnu.Akt-Mnu.Top)*20+19,0,0,0,128); rectangleRGBA(screen,Mnu.X,20+(Mnu.Akt-Mnu.Top)*20,Mnu.X+19,20+(Mnu.Akt-Mnu.Top)*20+19,255,255,255,128); } SDL_UpdateRect(screen,Mnu.X,0,20,400); }
void PortalManager::RenderPortals(RenderingCore *rCore, int srOx, int srOy) { for ( unsigned int i = 0; i < portalList.size(); i++ ) { SDL_Rect imageBox; imageBox.w = 64+40; imageBox.h = 64+40; imageBox.x = portalList[i].portalPosition.x-104/2 + srOx-20; imageBox.y = portalList[i].portalPosition.y-104/2 + srOy-20; pImage.SetAngle(portalList[i].portalAngle); pImage.SetPosition(portalList[i].portalPosition.x + srOx, portalList[i].portalPosition.y + srOy); //if ( flagsList[i].sledPosition.x + srOx + 64 > 0 && flagsList[i].sledPosition.x + srOx < SCREEN_WIDTH && flagsList[i].sledPosition.y + srOy + 64 > 0 && flagsList[i].sledPosition.y + srOy < SCREEN_HEIGHT ) { pImage.Render(rCore->ReturnScreenPointer()); //rCore->AppendUpdateRect(imageBox); std::stringstream str; str << portalList[i].ident; stringRGBA( rCore->ReturnScreenPointer(), portalList[i].portalPosition.x-104/2 + srOx-20+42, portalList[i].portalPosition.y-104/2 + srOy-20+42, str.str().c_str(), 0, 0, 0, 255 ); } } }
int main(int argc, char *argv[]) { SDL_Event ev,az; SDL_Surface *screen; SDL_Surface *kep; SDL_TimerID id; FILE *fp; int x, y,click=0,clicktwo=0,aut=0,quit=0,gomb=0,egerx,egery,nothinghappened=1; cell cells[MAX][MAX]={0}; kep=IMG_Load("sejt.png"); if(!kep) fprintf(stderr, "Nem sikerult betolteni a kepfajlt!\n"); /* SDL inicializálása és ablak megnyitása */ SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); screen=SDL_SetVideoMode(MAX*MERET+KERET*2+100, MAX*MERET+KERET*2-100, 0, SDL_FULLSCREEN); if (!screen) { fprintf(stderr, "Nem sikerult megnyitni az ablakot!\n"); exit(1); } SDL_WM_SetCaption("Game Of Life", "Game Of Life"); SDL_FillRect(screen, NULL, 0x433e3f); boxColor(screen,KERET/3,KERET/3,MAX*MERET+KERET*2-KERET/3,MAX*MERET+KERET*2-KERET/3,KERETSZIN); drawcell(cells,screen,kep); while(!quit) { boxColor(screen, MAX*MERET+KERET*2+10,KERET+5,MAX*MERET+KERET*2+90,KERET+40,0xFFDFD2FF); boxColor(screen, MAX*MERET+KERET*2+14,KERET+9,MAX*MERET+KERET*2+86,KERET+36,0xE5C8BDFF); stringRGBA(screen, MAX*MERET+KERET*2+20, KERET+19, "Leptetes", 255, 255, 255, 255); boxColor(screen, MAX*MERET+KERET*2+10,KERET+5+HEZAG,MAX*MERET+KERET*2+90,KERET+40+HEZAG,0xFFDFD2FF); boxColor(screen, MAX*MERET+KERET*2+14,KERET+9+HEZAG,MAX*MERET+KERET*2+86,KERET+36+HEZAG,0xE5C8BDFF); if(aut==0) stringRGBA(screen, MAX*MERET+KERET*2+15, KERET+69, "Szimul.be", 255, 255, 255, 255); else stringRGBA(screen, MAX*MERET+KERET*2+15, KERET+69, "Szimul.ki", 255, 255, 255, 255); boxColor(screen, MAX*MERET+KERET*2+10,KERET+5+HEZAG*2,MAX*MERET+KERET*2+90,KERET+40+HEZAG*2,0xFFDFD2FF); boxColor(screen, MAX*MERET+KERET*2+14,KERET+9+HEZAG*2,MAX*MERET+KERET*2+86,KERET+36+HEZAG*2,0xE5C8BDFF); stringRGBA(screen, MAX*MERET+KERET*2+26, KERET+19+HEZAG*2, "Torles", 255, 255, 255, 255); boxColor(screen, MAX*MERET+KERET*2+10,KERET+5+HEZAG*3,MAX*MERET+KERET*2+90,KERET+40+HEZAG*3,0xFFDFD2FF); boxColor(screen, MAX*MERET+KERET*2+14,KERET+9+HEZAG*3,MAX*MERET+KERET*2+86,KERET+36+HEZAG*3,0xE5C8BDFF); stringRGBA(screen, MAX*MERET+KERET*2+27, KERET+19+HEZAG*3, "Kilovo", 255, 255, 255, 255); filledCircleColor(screen,MAX*MERET+2*KERET+80,9,8,0xFFDFD2FF); filledCircleColor(screen,MAX*MERET+2*KERET+80,9,6,0xE5C8BDFF); stringRGBA(screen,MAX*MERET+KERET*2+77,6,"X",255,255,255,255); SDL_Flip(screen); while(SDL_PollEvent(&ev)){ switch(ev.type) { /*case SDL_KEYDOWN: switch(ev.key.keysym.sym) { case SDLK_s: mentes(cells); break; case SDLK_l: fp=fopen("save.txt","r"); for(y=0;y<MAX;y++) for(x=0;x<MAX;x++) fscanf(fp,"%d ",&cells[y][x].alive); fclose (fp); drawcell(cells,screen,kep); SDL_Flip(screen); break; } break;*/ case SDL_MOUSEBUTTONDOWN: if(ev.button.button==SDL_BUTTON_LEFT) { if(ev.button.x<=MAX*MERET+KERET){ egerx=holazeger(ev.button.x); egery=holazeger(ev.button.y); if(cells[egery][egerx].alive==1) cells[egery][egerx].alive=0; else cells[egery][egerx].alive=1; } else if(incircle(ev.button.x,ev.button.y,MAX*MERET+2*KERET+80,9,8)) quit=1; else if((ev.button.x<=MAX*MERET+KERET*2+90 && ev.button.x>=MAX*MERET+KERET*2+10) && (ev.button.y<=KERET+40 && ev.button.y>=KERET+5))//egyes lépés { round(cells); } else if((ev.button.x<=MAX*MERET+KERET*2+90 && ev.button.x>=MAX*MERET+KERET*2+10) && (ev.button.y<=KERET+90 && ev.button.y>=KERET+55))//szimulálás { if(aut==0) aut=1; else aut=0; } else if((ev.button.x<=MAX*MERET+KERET*2+90 && ev.button.x>=MAX*MERET+KERET*2+10) && (ev.button.y<=KERET+40+HEZAG*2 && ev.button.y>=KERET+5+HEZAG*2))//egyes lépés { for(y=0;y<MAX;y++) for(x=0;x<MAX;x++) cells[y][x].alive=0; } else if((ev.button.x<=MAX*MERET+KERET*2+90 && ev.button.x>=MAX*MERET+KERET*2+10) && (ev.button.y<=KERET+40+HEZAG*3 && ev.button.y>=KERET+5+HEZAG*3))//egyes lépés { fp=fopen("save.txt","r"); for(y=0;y<MAX;y++) for(x=0;x<MAX;x++) fscanf(fp,"%d ",&cells[y][x].alive); fclose (fp); drawcell(cells,screen,kep); SDL_Flip(screen); } drawcell(cells,screen,kep); SDL_Flip(screen); } break; case SDL_MOUSEBUTTONUP: if(ev.button.button==SDL_BUTTON_LEFT) { click=0; clicktwo=0; } break; case SDL_QUIT: quit=1; break; } } if(aut) { SDL_Delay(100); round(cells); drawcell(cells,screen,kep); SDL_Flip(screen); } } SDL_FreeSurface(kep); SDL_Quit(); exit(0); return 0; }
void Draw(SDL_Surface *screen) { FILE *file; char *myfont; char mytext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; /* Black screen */ ClearScreen(screen); /* Load a font and draw with it */ myfont=(char *)malloc(1792); file = fopen(RELPATH "Fonts/5x7.fnt","r"); fread(myfont,1792,1,file); fclose(file); gfxPrimitivesSetFont(myfont,5,7); stringRGBA(screen,10,10,mytext,255,255,255,255); free(myfont); /* Load a font and draw with it */ myfont=(char *)malloc(3328); // file = fopen(RELPATH "Fonts/7x13.fnt","r"); fread(myfont,3328,1,file); fclose(file); gfxPrimitivesSetFont(myfont,7,13); stringRGBA(screen,10,30,mytext,255,255,255,255); // file = fopen(RELPATH "Fonts/7x13B.fnt","r"); fread(myfont,3328,1,file); fclose(file); gfxPrimitivesSetFont(myfont,7,13); stringRGBA(screen,10,50,mytext,255,255,255,255); // file = fopen(RELPATH "Fonts/7x13O.fnt","r"); fread(myfont,3328,1,file); fclose(file); gfxPrimitivesSetFont(myfont,7,13); stringRGBA(screen,10,70,mytext,255,255,255,255); // free(myfont); /* Load a font and draw with it */ myfont=(char *)malloc(9216); // file = fopen(RELPATH "Fonts/9x18.fnt","r"); fread(myfont,9216,1,file); fclose(file); gfxPrimitivesSetFont(myfont,9,18); stringRGBA(screen,10,90,mytext,255,255,255,255); // file = fopen(RELPATH "Fonts/9x18B.fnt","r"); fread(myfont,9216,1,file); fclose(file); gfxPrimitivesSetFont(myfont,9,18); stringRGBA(screen,10,110,mytext,255,255,255,255); // free(myfont); /* Display by flipping screens */ SDL_UpdateRect(screen,0,0,0,0); while (1) { /* Events */ HandleEvent(); /* Delay to limit rate */ SDL_Delay(1000); } }
TEST ( T_Intersection, RectRect, off ) { // init and setup a video window if ( SDL_WasInit(SDL_INIT_VIDEO) == 0 ) { SDL_InitSubSystem( SDL_INIT_VIDEO ); } if ( !SDL_SetVideoMode( 1024, 1024, 0, 0 ) ) { fprintf( stderr, "Could not set video mode: %s\n", SDL_GetError() ); SDL_Quit(); exit( -1 ); } // static int mouse_x = 0; static int mouse_y = 0; static bool drawing_select = false; static bool drawing_create = false; // insert nodes to the tree typedef ex::Array<ex::recti_t> rects_t; rects_t rect_list; rects_t selected_rects; ex::recti_t mouse_rect; // main loop SDL_Event event; int quit = 0; while ( !quit ) { // ======================================================== // clear the buffer // ======================================================== ex::uint32 color = SDL_MapRGB( SDL_GetVideoSurface()->format, 20, 20, 20 ); SDL_FillRect( SDL_GetVideoSurface(), NULL, color ); // ======================================================== // process event // ======================================================== while ( SDL_PollEvent(&event) ) { switch ( event.type ) { // process mouse case SDL_MOUSEMOTION: { if ( drawing_create || drawing_select ) { mouse_rect.setInScreen ( mouse_x, mouse_y, event.button.x, event.button.y ); } } break; case SDL_MOUSEBUTTONDOWN: { mouse_x = event.button.x; mouse_y = event.button.y; mouse_rect.setInScreen ( mouse_x, mouse_y, event.button.x, event.button.y ); if ( event.button.button == SDL_BUTTON_RIGHT ) { drawing_create = true; } else if ( event.button.button == SDL_BUTTON_LEFT ) { drawing_select = true; } } break; case SDL_MOUSEBUTTONUP: { mouse_rect.setInScreen ( mouse_x, mouse_y, event.button.x, event.button.y ); if ( event.button.button == SDL_BUTTON_RIGHT ) { rect_list.push_back(mouse_rect); drawing_create = false; } else if ( event.button.button == SDL_BUTTON_LEFT ) { selected_rects.clear(); for ( rects_t::iterator iter = rect_list.begin(); iter != rect_list.end(); ++iter ) { if ( mouse_rect.contains(*iter) || ex::intersect::rect_rect( mouse_rect, *iter ) ) { selected_rects.push_back(*iter); } } drawing_select = false; } } break; case SDL_QUIT: quit = 1; break; default: break; } } // ======================================================== // rendering // ======================================================== // draw rects for ( rects_t::iterator iter = rect_list.begin(); iter != rect_list.end(); ++iter ) { rectangleRGBA ( SDL_GetVideoSurface(), (*iter).left(), (*iter).top(), (*iter).right(), (*iter).bot(), 255, 255, 255, 255 ); } // draw selected rects for ( rects_t::iterator iter = selected_rects.begin(); iter != selected_rects.end(); ++iter ) { rectangleRGBA ( SDL_GetVideoSurface(), (*iter).left(), (*iter).top(), (*iter).right(), (*iter).bot(), 255, 0, 0, 255 ); } // daw creating & selecting rect if ( drawing_create ) { rectangleRGBA ( SDL_GetVideoSurface(), mouse_rect.left(), mouse_rect.top(), mouse_rect.right(), mouse_rect.bot(), 0, 255, 255, 255 ); } if ( drawing_select ) { boxRGBA ( SDL_GetVideoSurface(), mouse_rect.left(), mouse_rect.top(), mouse_rect.right(), mouse_rect.bot(), 0, 128, 255, 128 ); rectangleRGBA ( SDL_GetVideoSurface(), mouse_rect.left(), mouse_rect.top(), mouse_rect.right(), mouse_rect.bot(), 0, 150, 255, 255 ); } // stringRGBA ( SDL_GetVideoSurface(), 10, 10, "Test Intersection RectRect", 255, 255, 255, 255 ); // SDL_Flip ( SDL_GetVideoSurface() ); } }
void InputScr(char *Title){ boxRGBA(screen,0,150,399,250,55,55,55,255); stringRGBA(screen,1,151,Title,255,255,255,255); SDL_UpdateRect(screen,0,150,400,100); }
void ProgramSystemMain::mainloop() { while(1) { //=========================== // すべてのイベントを処理する //=========================== SDL_Event event; Matrix21<int> _temp; while (SDL_PollEvent(&event)) { switch (event.type) { //画面サイズ変更 case SDL_VIDEORESIZE: SDL_FreeSurface(screen); screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 32,SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RLEACCEL | SDL_HWACCEL); DisplayReload(); break; //キー入力 case SDL_KEYDOWN: if(event.key.keysym.sym == SDLK_ESCAPE) { return; } if(event.key.keysym.sym == SDLK_RETURN && input[0].keyboard.ispush(SDLK_RALT)) { unsigned long flags=screen->flags,w=screen->w,h=screen->h; SDL_FreeSurface(screen); if(flags & SDL_FULLSCREEN) screen=SDL_SetVideoMode(w,h,32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RLEACCEL|SDL_HWACCEL); else screen=SDL_SetVideoMode(w,h,32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RLEACCEL|SDL_HWACCEL|SDL_FULLSCREEN); DisplayReload(); break; } input[0].keyboard.pushkey(event.key.keysym.sym); break; case SDL_KEYUP: input[0].keyboard.pullkey(event.key.keysym.sym); break; //マウス入力 case SDL_MOUSEMOTION: input[0].mouse.setpos(Matrix21<int>( event.motion.x, screen->h-event.motion.y) ); break; case SDL_MOUSEBUTTONDOWN: _temp = Matrix21<int>( event.button.x, screen->h-event.button.y ); switch(event.button.button) { case SDL_BUTTON_LEFT: input[0].mouse.setleft().push(_temp); break; case SDL_BUTTON_MIDDLE: input[0].mouse.setmiddle().push(_temp); break; case SDL_BUTTON_RIGHT: input[0].mouse.setright().push(_temp); break; } break; case SDL_MOUSEBUTTONUP: _temp = Matrix21<int>( event.button.x, screen->h-event.button.y ); switch(event.button.button) { case SDL_BUTTON_LEFT: input[0].mouse.setleft().pull(_temp); break; case SDL_BUTTON_MIDDLE: input[0].mouse.setmiddle().pull(_temp); break; case SDL_BUTTON_RIGHT: input[0].mouse.setright().pull(_temp); break; } break; //ジョイスティック入力(今回は無視) case SDL_JOYAXISMOTION: case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: break; //終わり case SDL_QUIT: return; //その他 default: break; } } //===== //実行 //===== update(); //========== //描画(SDL) //========== //static int dc=0; //dc = (dc>=4) ? 0 : dc+1; //if(dc==0){ if(!fpscontrol.onlyUpdate()) { draw(); { char _str[30]; sprintf(_str,"FPS::%5.2lf",fpscontrol.getFPS()); stringRGBA(screen, screen->w-81, screen->h-9, _str, 0xff, 0xff, 0xff, 0xff); } SDL_Flip(screen); } fpscontrol.delay(); //========== //全部の後。 //========== after_all(); //=============== //いらないの削除 //=============== std::list<SystemState*>::iterator it=nowstates.begin(); for(; it!=nowstates.end();) { if(!(*it)->isNeed) { delete *it; it = nowstates.erase(it); } else it++; } } }
void Renderer::renderText(std::string text, const SDL_Point &point, const SDL_Color &color) { stringRGBA(this->renderer, point.x, point.y, text.c_str(), color.r, color.g, color.b, color.a); }
void AccuracyTest1(SDL_Surface *screen) { SDL_Surface* testx1; SDL_Surface* testx2; SDL_Rect r; SDL_Rect target; SDL_Surface* ref; int size, halfsize, doublesize; printf("%s\n", messageText); for (size = 10; size < 200; size += 2) { HandleEvent(); ClearScreen(screen); stringRGBA(screen, 8, 8, messageText, 255, 255, 255, 255); halfsize = size / 2; doublesize = size * 2; printf (" zoom from %i to %i\n", size, doublesize); // Set up test surfaces testx1 = SDL_CreateRGBSurface(SDL_SWSURFACE, size, size, 24, 0, 0, 0, 0); r.x = 0; r.y = 0; r.w = halfsize; r.h = halfsize; SDL_FillRect(testx1, &r, 0x339933); r.x = halfsize; r.y = halfsize; SDL_FillRect(testx1, &r, 0x993399); r.x = 0; r.y = halfsize; SDL_FillRect(testx1, &r, 0x999933); r.x = halfsize; r.y = 0; SDL_FillRect(testx1, &r, 0x333399); testx2 = zoomSurface(testx1, 2.0, 2.0, 0); ref = SDL_CreateRGBSurface(SDL_SWSURFACE, size, size, 24, 0, 0, 0, 0); r.w = size; r.h = size; r.x = 0; r.y = 0; SDL_FillRect(ref, &r, 0xFFFFFF); /* Validation display */ target.x = 0; target.y = 20; target.w = 0; target.h = 0; SDL_BlitSurface(testx1, 0, screen, &target); target.x = size; target.y = 20; SDL_BlitSurface(ref, 0, screen, &target); target.x = 0; target.y = 20 + size; SDL_BlitSurface(ref, 0, screen, &target); target.x = doublesize + 20; target.y = 20; SDL_BlitSurface(testx2, 0, screen, &target); target.x = doublesize + doublesize + 20; target.y = 20; SDL_BlitSurface(ref, 0, screen, &target); target.x = doublesize + 20; target.y = 20 + doublesize; SDL_BlitSurface(ref, 0, screen, &target); SDL_FreeSurface(testx1); SDL_FreeSurface(testx2); SDL_FreeSurface(ref); /* Display by flipping screens */ SDL_Flip(screen); /* Always delay */ SDL_Delay(250); /* Maybe add extra delay */ if (delay>0) { SDL_Delay(delay); } } SDL_Delay(1000); }
unsigned int viewer(state* s, double* a, double reward, void* instance) { char str[255]; double cartPoleScalingFactor = (screenWidth / 2.0) - 20; double ratioPixels = cartPoleScalingFactor / (2.0 * parameters[1]); int done = 0; SDL_Event event; SDL_FillRect(screen, NULL, SDL_MapRGBA(screen->format, 255,255,255,255)); if(a != NULL) { sprintf(str, "Applied X Force : % f", ((parameters[7] + parameters[7]) * a[0]) - parameters[7]); stringRGBA(screen, 5, 5, str, 0, 0, 0, 255); } sprintf(str, "Angular Position: % f", s->angularPosition); stringRGBA(screen, 5, 15, str, 0, 0, 0, 255); sprintf(str, "Angular Velocity: % f", s->angularVelocity); stringRGBA(screen, 5, 25, str, 0, 0, 0, 255); sprintf(str, "X Position : % f", s->xPosition); stringRGBA(screen, 5, 35, str, 0, 0, 0, 255); sprintf(str, "X Velocity : % f", s->xVelocity); stringRGBA(screen, 5, 45, str, 0, 0, 0, 255); sprintf(str, "Reward : % f", reward); stringRGBA(screen, 5, 55, str, 0, 0, 0, 255); stringRGBA(screen, 5, screenHeight - 10, "Press escape to quit", 0, 0, 0, 255); lineRGBA(screen, 10, screenHeight / 2.0, (screenWidth / 2.0) - 10, screenHeight / 2.0, 0, 0, 0, 255); drawPendulum(s, 0, 0, 0, 255, ratioPixels); if(a != NULL) { if(a[0] < 0.5) filledTrigonRGBA(screen, (screenWidth / 4.0) - 10, screenHeight * 0.9, (screenWidth / 4.0), (screenHeight * 0.9) - 5, (screenWidth / 4.0) - 10, (screenHeight * 0.9) - 10 , 0, 0, 0, 255); else if(a[0] > 0.5) filledTrigonRGBA(screen, (screenWidth / 4.0) + 10, screenHeight * 0.9, (screenWidth / 4.0) + 20, (screenHeight * 0.9) - 5, (screenWidth / 4.0) + 10, (screenHeight * 0.9) - 10, 0, 0, 0, 255); else boxRGBA(screen, (screenWidth / 4.0) - 5, screenHeight * 0.9, (screenWidth / 4.0) + 5, (screenHeight * 0.9) - 10, 0, 0, 0, 255); } if(algorithm_drawingProcedure != NULL) algorithm_drawingProcedure(screen, screenWidth, screenHeight, instance); SDL_Flip(screen); while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; if(event.key.keysym.sym == SDLK_SPACE) done = waitForAnotherSpace(); break; case SDL_QUIT: done = 1; break; } } SDL_framerateDelay(&fpsm); return done; }
void Renderer::String(Point p, string s, Uint8 rr, Uint8 gg, Uint8 bb, Uint8 aa){ stringRGBA(_renderer, p.x(), p.y(), s.c_str(), rr, gg, bb, aa); }
void Draw (SDL_Surface *screen, char *bmpfile) { char messageText[128]; Uint32 rmask, gmask, bmask, amask; SDL_Surface *picture; SDL_Surface *mapped_picture; SDL_Surface *rotozoom_picture; SDL_PixelFormat *pixelFormat; Uint8 *grayscale, *map, *curmap; double *unrelaxed, *relaxed, *currelax; int mapsize, relaxsize; int rowskip; char *pixel; Uint32 p; int x, y; Uint8 r, g, b, a; double dy; double t, s; int i; double c1, c2, c3, c4, ca; Uint8 lookupTable[256]; double zw, zh, zf; /* SDL interprets each pixel as a 32-bit number, so our masks must depend on the endianness (byte order) of the machine */ #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif /* Load the image into a surface */ printf("Loading picture: %s\n", bmpfile); picture = SDL_LoadBMP(bmpfile); if ( picture == NULL ) { fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); return; } /* Convert image to a brightness map */ printf("Allocating workbuffers\n"); mapsize = picture->w * picture->h; relaxsize = mapsize * sizeof(double); grayscale = (Uint8 *)malloc(mapsize); map = (Uint8 *)malloc(mapsize); unrelaxed = (double *)malloc(relaxsize); relaxed = (double *)malloc(relaxsize); if ((grayscale == NULL) || (map == NULL) || (unrelaxed == NULL) || (relaxed == NULL)) { fprintf(stderr, "Out of memory\n"); return; } memset(grayscale, 0, mapsize); memset(map, 0, mapsize); memset(unrelaxed, 0, relaxsize); memset(relaxed, 0, relaxsize); printf("Converting image to brightness map\n"); pixel = picture->pixels; pixelFormat = picture->format; rowskip = (picture->pitch - picture->w * picture->format->BytesPerPixel); curmap = grayscale; for (y=0; y < picture->h; y++) { for (x=0; x < picture->w; x++) { // Get RGB p = getPixel(picture, x, y); SDL_GetRGBA(p, pixelFormat, &r, &g, &b, &a); // Calculate luminance (Y = 0.3R + 0.59G + 0.11B;) dy = (0.30 * r) + (0.59 * g) + (0.11 * b); if (dy<0.0) { dy=0.0; } else if (dy>255.0) { dy=255.0; } *curmap = (Uint8)dy; // Next pixel pixel += picture->format->BytesPerPixel; curmap++; } // Next row pixel += rowskip; } /* --- Prepare relaxation loop --- */ /* Binarize luminance map */ SDL_imageFilterBinarizeUsingThreshold(grayscale, map, mapsize, threshold); /* Create cos^5 based lookup table */ t = 0.0; for (i = 0; i < 256; i++) { s = 1.0 - 0.5 * (1.0 + cos(t)); s = 255.0 * s * s * s * s * s; lookupTable[i] = (Uint8)s; t += ((double)contours*2.0*3.141592653589/128.0); } /* Create new surface for relaxed image */ mapped_picture = SDL_CreateRGBSurface(SDL_SWSURFACE, picture->w, picture->h, 32, rmask, gmask, bmask, amask); if (mapped_picture == NULL) { fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError()); return; } /* Apply relaxation algorithm */ printf("Applying Laplacian relaxation: %i iterations\n", iterations); // Iterate to relax for (i = 0; i <= iterations; i++) { // Backup original memcpy(unrelaxed, relaxed, relaxsize); // Average into relaxed for (x=0; x < picture->w; x++) { for (y=0; y < picture->h; y++) { // up c1 = GetPotential(map, grayscale, unrelaxed, x, y-1, picture->w, picture->h); // down c2 = GetPotential(map, grayscale, unrelaxed, x, y+1, picture->w, picture->h); // left c3 = GetPotential(map, grayscale, unrelaxed, x-1, y, picture->w, picture->h); // right c4 = GetPotential(map, grayscale, unrelaxed, x+1, y, picture->w, picture->h); // average and store ca = ((c1 + c2 + c3 + c4)/4.0); relaxed[x+y*picture->w] = ca; } } // Draw only sometimes if (((i % 10)==0) || (i==iterations)) { /* --- Create image with contour map --- */ /* Fill output surface via colormap */ currelax = relaxed; for (y=0; y<mapped_picture->h; y++) { for (x=0; x<mapped_picture->w; x++) { if (map[x+y*picture->w]!=0) { r = g = b = grayscale[x+y*picture->w]; } else { r = g = b = lookupTable[(Uint8)*currelax]; } pixelRGBA(mapped_picture, x, y, r, g, b, 255); currelax++; } } /* --- Scale and draw to screen --- */ /* Scale to screen size */ zw = (double)screen->w/(double)mapped_picture->w; zh = (double)screen->h/(double)mapped_picture->h; zf = (zw < zh) ? zw : zh; if ((rotozoom_picture=zoomSurface(mapped_picture, zf, zf, 1))==NULL) { fprintf(stderr, "Rotozoom failed: %s\n", SDL_GetError()); return; } /* Draw surface to screen */ if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, NULL) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); return; } SDL_FreeSurface(rotozoom_picture); /* Info */ if (i != iterations) { sprintf(messageText,"%i", i); stringRGBA(screen, 8, 8, messageText, 255, 255, 255, 255); } /* Display by flipping screens */ SDL_Flip(screen); } /* Maybe quit */ HandleEvent(); } /* Save final picture */ if (SDL_SaveBMP(mapped_picture, "result.bmp") <0) { fprintf(stderr, "Save BMP failed: %s\n", SDL_GetError()); return; } free(map); free(grayscale); free(unrelaxed); free(relaxed); SDL_FreeSurface(picture); SDL_FreeSurface(mapped_picture); return; }
void RotatePicture (SDL_Surface *screen, SDL_Surface *picture, int rotate, int flip, int smooth) { SDL_Surface *rotozoom_picture; SDL_Rect dest; int framecount, framemax, frameinc; double angle, zoomf, zoomfx, zoomfy; fprintf(stderr, "%s\n", messageText); /* Rotate and display the picture */ framemax=4*360; frameinc=1; for (framecount=-360; framecount<framemax; framecount += frameinc) { if ((framecount % 360)==0) frameinc++; HandleEvent(); ClearScreen(screen); zoomf=(float)(framecount+2*360)/(float)framemax; zoomf=1.5*zoomf*zoomf; /* Are we in flipping mode? */ if (flip) { /* Flip X factor */ if (flip & 1) { zoomfx=-zoomf; } else { zoomfx=zoomf; } /* Flip Y factor */ if (flip & 2) { zoomfy=-zoomf; } else { zoomfy=zoomf; } angle=framecount*rotate; if (((framecount % 120)==0) || (delay>0)) { printf (" Frame: %i Rotate: angle=%.2f Zoom: x=%.2f y=%.2f\n",framecount,angle,zoomfx,zoomfy); } if ((rotozoom_picture=rotozoomSurfaceXY (picture, angle, zoomfx, zoomfy, smooth))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); break; } SDL_FreeSurface(rotozoom_picture); } } else { angle=framecount*rotate; if ((framecount % 120)==0) { printf (" Frame: %i Rotate: angle=%.2f Zoom: f=%.2f \n",framecount,angle,zoomf); } if ((rotozoom_picture=rotozoomSurface (picture, angle, zoomf, smooth))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); break; } SDL_FreeSurface(rotozoom_picture); } } stringRGBA(screen, 8, 8, messageText, 255, 255, 255, 255); /* Display by flipping screens */ SDL_Flip(screen); /* Maybe delay */ if (delay>0) { SDL_Delay(delay); } } if (rotate) { /* Final display with angle=0 */ HandleEvent(); ClearScreen(screen); if (flip) { if ((rotozoom_picture=rotozoomSurfaceXY (picture, 0.01, zoomfx, zoomfy, smooth))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); return; } SDL_FreeSurface(rotozoom_picture); } } else { if ((rotozoom_picture=rotozoomSurface (picture, 0.01, zoomf, smooth))!=NULL) { dest.x = (screen->w - rotozoom_picture->w)/2;; dest.y = (screen->h - rotozoom_picture->h)/2; dest.w = rotozoom_picture->w; dest.h = rotozoom_picture->h; if ( SDL_BlitSurface(rotozoom_picture, NULL, screen, &dest) < 0 ) { fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); return; } SDL_FreeSurface(rotozoom_picture); } } stringRGBA(screen, 8, 8, messageText, 255, 255, 255, 255); /* Display by flipping screens */ SDL_Flip(screen); /* Maybe delay */ if (delay>0) { SDL_Delay(delay); } } /* Pause for a sec */ SDL_Delay(1000); }
void Draw(SDL_Surface *screen) { int i, rotation; char *myfont; char mytext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int x,y,yold; /* Black screen */ ClearScreen(screen); y=0; /* Try all horizontal rotations */ rotation = 0; gfxPrimitivesSetFontRotation(rotation); /* Render all fonts */ for (i=0; i<NUM_SDLGFX_FONTS; i++) { fprintf(stderr,"Drawing Font: size %ix%i, file '%s', %i bytes, rotation %i\n",fontw[i], fonth[i], fontfile[i],fontsize[i], rotation); /* Reset line pos */ x=4; myfont = NULL; if (i>0) { myfont=LoadFontFile(i); } /* Set font data and use it */ gfxPrimitivesSetFont(myfont,fontw[i],fonth[i]); y += fonth[i]; stringRGBA(screen,x,y,fontfile[i],255,255,255,255); x += 100; stringRGBA(screen,x,y,mytext,255,255,255,255); y += 10; if (i>0) { /* Clean up font-data */ free(myfont); } } y += 20; yold = y; rotation = 2; gfxPrimitivesSetFontRotation(rotation); /* Render all fonts */ for (i=0; i<NUM_SDLGFX_FONTS; i++) { fprintf(stderr,"Drawing Font: size %ix%i, file '%s', %i bytes, rotation %i\n",fontw[i], fonth[i], fontfile[i],fontsize[i], rotation); /* Reset line pos */ x=WIDTH - 14; myfont = NULL; if (i>0) { myfont=LoadFontFile(i); } /* Set font data and use it */ gfxPrimitivesSetFont(myfont,fontw[i],fonth[i]); y += fonth[i]; stringRGBA(screen,x,y,fontfile[i],255,255,255,255); x -= 100; stringRGBA(screen,x,y,mytext,255,255,255,255); y += 10; if (i>0) { /* Clean up font-data */ free(myfont); } } y += 20; /* Try all vertical rotations */ rotation = 1; gfxPrimitivesSetFontRotation(rotation); x = 14; /* Render all fonts */ for (i=0; i<NUM_SDLGFX_FONTS; i++) { fprintf(stderr,"Drawing Font: size %ix%i, file '%s', %i bytes, rotation %i\n",fontw[i], fonth[i], fontfile[i],fontsize[i], rotation); /* Reset line pos */ y=yold; myfont = NULL; if (i>0) { myfont=LoadFontFile(i); } /* Set font data and use it */ gfxPrimitivesSetFont(myfont,fontw[i],fonth[i]); x += fonth[i]; stringRGBA(screen,x,y,fontfile[i],255,255,255,255); y += 100; stringRGBA(screen,x,y,mytext,255,255,255,255); x += 10; if (i>0) { /* Clean up font-data */ free(myfont); } } x += 20; rotation = 3; gfxPrimitivesSetFontRotation(rotation); /* Render all fonts */ for (i=0; i<NUM_SDLGFX_FONTS; i++) { fprintf(stderr,"Drawing Font: size %ix%i, file '%s', %i bytes, rotation %i\n",fontw[i], fonth[i], fontfile[i],fontsize[i], rotation); /* Reset line pos */ y=HEIGHT - 14; myfont = NULL; if (i>0) { if (i>0) { myfont=LoadFontFile(i); } /* Set font data and use it */ gfxPrimitivesSetFont(myfont,fontw[i],fonth[i]); x += fonth[i]; stringRGBA(screen,x,y,fontfile[i],255,255,255,255); y -= 100; stringRGBA(screen,x,y,mytext,255,255,255,255); x += 10; if (i>0) { /* Clean up font-data */ free(myfont); } } /* Display by flipping screens */ SDL_Flip(screen); } }
void Renderer::renderText(std::string text, const SDL_Point &point, const SDL_Color &color, float scaleX, float scaleY) { SDL_RenderSetScale(this->renderer, scaleX, scaleY); stringRGBA(this->renderer, point.x/scaleX, point.y/scaleY, text.c_str(), color.r, color.g, color.b, color.a); SDL_RenderSetScale(this->renderer, 1, 1); }
unsigned int viewer(state* s, action* a, double reward, void* instance) { char str[255]; double ratioPixels = ((screenWidth / 2.0) - 20) / (2.0 * parameters[1]); int done = 0; SDL_Event event; SDL_FillRect(screen, NULL, SDL_MapRGBA(screen->format, 255,255,255,255)); if(a != NULL) { sprintf(str, "Applied X Force 1: % f", a->xAcceleration1); stringRGBA(screen, 5, 5, str, 0, 0, 0, 255); sprintf(str, "Applied X Force 2: % f", a->xAcceleration2); stringRGBA(screen, 5, 25, str, 0, 0, 0, 255); } sprintf(str, "Angular Position1: % f", s->angularPosition1); stringRGBA(screen, 5, 15, str, 0, 0, 0, 255); sprintf(str, "Angular Position2: % f", s->angularPosition2); stringRGBA(screen, 5, 35, str, 0, 0, 0, 255); sprintf(str, "Distance : % f", fabs(s->xPosition2 - s->xPosition1)); stringRGBA(screen, 5, 45, str, 0, 0, 0, 255); sprintf(str, "Reward : % f", reward); stringRGBA(screen, 5, 55, str, 0, 0, 0, 255); lineRGBA(screen, 10, screenHeight / 2.0, screenHeight - 10, screenHeight / 2.0, 0, 0, 0, 255); if(algorithm_drawingProcedure != NULL) algorithm_drawingProcedure(screen, screenWidth, screenHeight, instance); drawDIPS(screen, s, 0, 0, 0, 255, ratioPixels); if(a != NULL) { if(a->xAcceleration2 < 0) filledTrigonRGBA(screen, ((screenWidth / 2.0) * 3.0 / 4.0) - 10, screenHeight * 0.9, ((screenWidth / 2.0) * 3.0 / 4.0) - 20, (screenHeight * 0.9) - 5, ((screenWidth / 2.0) * 3.0 / 4.0) - 10, (screenHeight * 0.9) - 10 , 0, 0, 0, 255); else if(a->xAcceleration2 > 0) filledTrigonRGBA(screen, ((screenWidth / 2.0) * 3.0 / 4.0) + 10, screenHeight * 0.9, ((screenWidth / 2.0) * 3.0 / 4.0) + 20, (screenHeight * 0.9) - 5, ((screenWidth / 2.0) * 3.0 / 4.0) + 10, (screenHeight * 0.9) - 10, 0, 0, 0, 255); else boxRGBA(screen, ((screenWidth / 2.0) * 3.0 / 4.0) - 5, screenHeight * 0.9, ((screenWidth / 2.0) * 3.0 / 4.0) + 5, (screenHeight * 0.9) - 10, 0, 0, 0, 255); if(a->xAcceleration1 < 0) filledTrigonRGBA(screen, (screenWidth / 8.0) - 10, screenHeight * 0.9, (screenWidth / 8.0) - 20, (screenHeight * 0.9) - 5, (screenWidth / 8.0) - 10, (screenHeight * 0.9) - 10 , 0, 0, 0, 255); else if(a->xAcceleration1 > 0) filledTrigonRGBA(screen, (screenWidth / 8.0) + 10, screenHeight * 0.9, (screenWidth / 8.0) + 20, (screenHeight * 0.9) - 5, (screenWidth / 8.0) + 10, (screenHeight * 0.9) - 10, 0, 0, 0, 255); else boxRGBA(screen, (screenWidth / 8.0) - 5, screenHeight * 0.9, (screenWidth / 8.0) + 5, (screenHeight * 0.9) - 10, 0, 0, 0, 255); } if(algorithm_drawingProcedure != NULL) algorithm_drawingProcedure(screen, screenWidth, screenHeight, instance); SDL_Flip(screen); while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: if(event.key.keysym.sym == SDLK_ESCAPE) done = 1; if(event.key.keysym.sym == SDLK_SPACE) done = waitForAnotherSpace(); break; case SDL_QUIT: done = 1; break; } } SDL_framerateDelay(&fpsm); return done; }