void Vector::visualize(SDL_Surface *dst) { SDL_Rect r = toRect(); SDL_FillRect(dst, &r, SDL_MapRGB(dst->format, 0xFF, 0x00, 0x00)); }
int main(void) { SDL_Surface *scr = wInitSDL(); DrawFillRect(scr, NULL, SDL_MapRGB(scr->format, 0, 0, 0)); wInitTheme(NULL); nSDL_Font *font = nSDL_LoadFont(NSDL_FONT_VGA, 255, 255, 255); nSDL_DrawStringCF(scr, font, 5, 5, "Couco\45 u !"); SDL_Flip(scr); wait_key_pressed(); nSDL_FreeFont(font); /* // Déclaration des widgets Widget *mainWidget = wWindow("Aide"); Widget *tabs = wTab(); // 1er onglet Widget *body1 = wBasicLayout(0); Widget *subody1 = wHorizontalLayout(0); Widget *im_tbtton = wPixmapNTI(image_buttonScratchpad); Widget *navigation = wText("Use the T-Button to navigate between tabs.\n\nIf you maintain this button while using RIGHT or LEFT buttons, you will be able to select your tab.\n\nMaintaining the T-Button plus pushing DEL will delete the selected tab from your work space.\n\nTo navigate faster in your texts, use CTRL+Directional Arrow.", 15); //2e onglet Widget *keys = wText("DOC - Quicksave the current file\nSHIFT + DOC - Quickave all files\n\nSHIFT + Directional Arrow - Select text\nCTRL + VAR - Copy selection\nVAR - Paste selection\n\nUse CTRL + (Character Button) or SHIFT + (Character Button) to get another character.\n\nHere are some useful examples :\nCTRL + ' , ' --> ;\nCTRL + ' 0 ' --> :\nCTRL + '.' --> !\nCTRL + '(-)' --> ?\nqu'est-ce qui bug au fond ??? Est-ce quand j'ai un wText avec progressbar mais non éditable ???\nCTRL+'2' = '\"'\nCTRL+'/' '\%'\nCTRL+'(' = '['\nSHIFT+'(' = '{'\nSHIFT+1 = '<'\nSHIT+'2' = '_'\nSHIFT+'3' = '>'\netc...\n\nUse CTRL+'?!>' to get some special characters. ", 17); // // 3e onglet Widget *body3 = wGridLayout(1, 3,0); Widget *text1 = wText("Rename a file with '.py' or '.py.tns' extension to get Python's syntax highlights.", 3); Widget *text2 = wText("You can then click ENTER at any time to execute and test your program.", 3); Widget *text3 = wText("If you placed the Micropython executable into a specific location, indicate his path via the 'Options' dialog box.", 3); wText_SetUnEditable(navigation); wText_SetUnEditable(keys); wText_SetUnEditable(text1); wText_SetUnEditable(text2); wText_SetUnEditable(text3); wTab_AddTab(tabs, "Navigation", body1); wTab_AddTab(tabs, "Keys", keys); wTab_AddTab(tabs, "Python", body3); wAddWidget(mainWidget, tabs); wAddWidget(body1, subody1); wAddWidget(subody1, im_tbtton); wAddWidget(subody1, wExLabel("<--- This is the awesome T-BUTTON.", ALIGN_LEFT, nSDL_LoadFont(NSDL_FONT_VGA, 204,15,225))); wAddWidget(body1, navigation); wAddWidget(body3, text1); wAddWidget(body3, text2); wAddWidget(body3, text3); wSetHeight(subody1, 24); wSetWidth(mainWidget, 300); wSetHeight(mainWidget, 220); wExecConstruct(mainWidget);//*/ wCloseTheme(); SDL_Quit(); return 1; }
void GUI::set_bg_colour(int r, int g, int b) { bgcolour = SDL_MapRGB(screen->format, r, g, b); bgimg = NULL; }
void Rasterizer::fillHalfFlatTriangle(const Vertex &v1, const Vertex &v2, const Vertex &v3, int orientation, SDL_Surface* screen) { if (orientation != RASTERIZER_BREAK) { Vertex vA, vB, vC; float invslope1; float invslope2; if ((int)v1.y == (int)v2.y) { vA = v3; vB = v1; vC = v2; } else if ((int)v1.y == (int)v3.y) { vA = v2; vB = v1; vC = v3; } else { if (v1.y > v2.y && v1.y > v3.y) { vA = v1; vB = v2; vC = v3; } else if (v2.y > v1.y && v2.y > v3.y) { vA = v2; vB = v1; vC = v3; } else if (v3.y > v1.y && v3.y > v2.y) { vA = v3; vB = v1; vC = v2; } } orientation = RASTERIZER_BREAK; if (vA.y > vB.y && vA.y > vC.y && vB.y == vC.y) orientation = RASTERIZE_TRIANGLE_DOWN; else if (vA.y < vB.y && vA.y < vC.y && vB.y == vC.y) orientation = RASTERIZE_TRIANGLE_UP; /*else if (vB.y != vC.y) orientation = RASTERIZE_TRIANGLE_SPLIT;*/ float lineX1 = vA.x; float lineX2 = vB.x; SDL_PixelFormat* fmt = screen->format; Uint32 rasterColour = SDL_MapRGB(fmt, 0, 255, 0); Uint32 rasterColour2 = SDL_MapRGB(fmt, 0, 0, 255); if (orientation == RASTERIZE_TRIANGLE_UP) { lineX2 = vA.x; invslope1 = (vB.x - vA.x) / (vB.y - vA.y); invslope2 = (vC.x - vA.x) / (vC.y - vA.y); for (float lineY = vA.y; lineY <= vB.y; lineY += RASTERIZER_GRANULARITY) { /*if (lineX1 <= 0) { lineX1 = 0.1f; break; } if (lineX2 <= 0) { lineX2 = 0.1f; break; } if (lineY <= 0) { lineY = 0.1f; break; } if (lineX1 >= 800) { lineX1 = 600; break; } if (lineX2 >= 800) { lineX2 = 600; break; } if (lineY >= 600) { lineY = 400; break; }*/ if (ValidateScreenCoord(lineX1, 0) && ValidateScreenCoord(lineX2, 0) && ValidateScreenCoord(lineY, 1)) { Draw_Line(screen, lineX1, lineY, lineX2, lineY, rasterColour); } //Draw_FillCircle(SDL_GetVideoSurface(), lineX2, lineY, 2, SDL_MapRGB(fmt, 255, 0, 255)); lineX1 += invslope1; lineX2 += invslope2; } } else if (orientation == RASTERIZE_TRIANGLE_DOWN) { lineX2 = vA.x; invslope1 = (vA.x - vB.x) / (vA.y - vB.y); invslope2 = (vA.x - vC.x) / (vA.y - vC.y); for (float lineY = vA.y; lineY >= vB.y; lineY -= RASTERIZER_GRANULARITY) { /*if (lineX1 <= 0) { lineX1 = 0.1f; break; } if (lineX2 <= 0) { lineX2 = 0.1f; break; } if (lineY <= 0) { lineY = 0.1f; break; } if (lineX1 >= 800) { lineX1 = 600; break; } if (lineX2 >= 800) { lineX2 = 600; break; } if (lineY >= 600) { lineY = 400; break; }*/ if (ValidateScreenCoord(lineX1, 0) && ValidateScreenCoord(lineX2, 0) && ValidateScreenCoord(lineY, 1)) { Draw_Line(screen, lineX1, lineY, lineX2, lineY, rasterColour2); } //Draw_FillCircle(SDL_GetVideoSurface(), lineX1, lineY, 2, SDL_MapRGB(fmt, 0, 255, 255)); lineX1 -= invslope1; lineX2 -= invslope2; } } else if (orientation == RASTERIZE_TRIANGLE_SPLIT) { Vertex v4; if (vC.x > vA.x) v4.x = vA.x + ((vB.y - vA.y) / (vC.y - vA.y)) * (vC.x - vA.x); else v4.x = vA.x + ((vB.y - vA.y) / (vC.y - vA.y)) * (vA.x - vC.x); if (vB.y > vC.y) { v4.y = vC.y; //vB = vC; } else { v4.y = vB.y; } //Draw_FillCircle(SDL_GetVideoSurface(), v4.x, v4.y, 7, SDL_MapRGB(fmt, 0, 150, 255)); //Rasterizer::fillHalfFlatTriangle(vA, vB, v4, orientation, screen); //Rasterizer::fillHalfFlatTriangle(vB, v4, vC, orientation, screen); } } }
void Object::setColorKey(int aRed, int aGreen, int aBlue) { if(obj != NULL) { SDL_SetColorKey(obj, SDL_SRCCOLORKEY, SDL_MapRGB(obj->format, aRed, aGreen, aBlue)); } }
void set_color(double r, double g, double b) { current_color = SDL_MapRGB(screen->format, r*255, g*255, b*255); }
int RunModeTests(SDL_Surface *screen) { Uint32 then, now; Uint32 frames; float seconds; int i; Uint8 r, g, b; SDL_Surface *bmp, *bmpcc, *tmp; SDL_Event event; while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* First test fills and screen update speed */ printf("Running color fill and fullscreen update test\n"); then = SDL_GetTicks(); frames = 0; for ( i = 0; i < 256; ++i ) { r = i; g = 0; b = 0; SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); SDL_Flip(screen); ++frames; } for ( i = 0; i < 256; ++i ) { r = 0; g = i; b = 0; SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); SDL_Flip(screen); ++frames; } for ( i = 0; i < 256; ++i ) { r = 0; g = 0; b = i; SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); SDL_Flip(screen); ++frames; } now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, seconds, (float)frames / seconds); } else { printf("%d fills and flips in zero seconds!n", frames); } /* clear the screen after fill test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the generic blit test */ bmp = SDL_LoadBMP("sample.bmp"); if ( ! bmp ) { printf("Couldn't load sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ", bmp->w, bmp->h, bmp->format->BitsPerPixel); PrintFlags(bmp->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmp, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } /* clear the screen after blit test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the colorkeyed blit test */ bmpcc = SDL_LoadBMP("sample.bmp"); if ( ! bmpcc ) { printf("Couldn't load sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ", bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels); PrintFlags(bmpcc->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmpcc, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } /* clear the screen after cc blit test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the generic blit test */ tmp = bmp; bmp = SDL_DisplayFormat(bmp); SDL_FreeSurface(tmp); if ( ! bmp ) { printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running display format blit test: %dx%d at %d bpp, flags: ", bmp->w, bmp->h, bmp->format->BitsPerPixel); PrintFlags(bmp->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmp, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } /* clear the screen after blit test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the colorkeyed blit test */ tmp = bmpcc; bmpcc = SDL_DisplayFormat(bmpcc); SDL_FreeSurface(tmp); if ( ! bmpcc ) { printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running display format cc blit test: %dx%d at %d bpp, flags: ", bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); PrintFlags(bmpcc->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmpcc, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } /* clear the screen after cc blit test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the alpha blit test only if screen bpp>8 */ if (bmp->format->BitsPerPixel>8) { SDL_FreeSurface(bmp); bmp = SDL_LoadBMP("sample.bmp"); SDL_SetAlpha(bmp, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ tmp = bmp; bmp = SDL_DisplayFormat(bmp); SDL_FreeSurface(tmp); if ( ! bmp ) { printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running display format alpha blit test: %dx%d at %d bpp, flags: ", bmp->w, bmp->h, bmp->format->BitsPerPixel); PrintFlags(bmp->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmp, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d alpha blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } } /* clear the screen after alpha blit test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the cc+alpha blit test only if screen bpp>8 */ if (bmp->format->BitsPerPixel>8) { SDL_FreeSurface(bmpcc); bmpcc = SDL_LoadBMP("sample.bmp"); SDL_SetAlpha(bmpcc, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels); tmp = bmpcc; bmpcc = SDL_DisplayFormat(bmpcc); SDL_FreeSurface(tmp); if ( ! bmpcc ) { printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running display format cc+alpha blit test: %dx%d at %d bpp, flags: ", bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); PrintFlags(bmpcc->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmpcc, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d cc+alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d cc+alpha blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } } SDL_FreeSurface(bmpcc); SDL_FreeSurface(bmp); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } return 1; }
void gui_show_listbox(gui_listbox *lb) { int i, item; SDL_Rect rect; if (lb == NULL) return; if (!lb->visible) return; /* draw the under area first */ if (lb->trans_area == NULL) { SDL_Surface *area; SDL_Rect src, dest; area = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, lb->w - 17, lb->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); assert(area); rect.x = 0; rect.y = 0; rect.w = area->w; rect.h = area->h; SDL_FillRect(area, &rect, SDL_MapRGB(area->format, 0, 0, 0)); SDL_SetAlpha(area, SDL_SRCALPHA, 93); rect.x = lb->x; rect.y = lb->y; rect.w = area->w; rect.h = area->h; blit_surface(area, NULL, &rect, 0); SDL_FreeSurface(area); /* now that the trans area is drawn, back up that area there */ lb->trans_area = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, lb->w - 17, lb->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); src.x = lb->x; src.y = lb->y; src.w = lb->trans_area->w; src.h = lb->trans_area->h; dest.x = 0; dest.y = 0; dest.w = src.w; dest.h = src.h; SDL_BlitSurface(screen, &src, lb->trans_area, &dest); } else { rect.x = lb->x; rect.y = lb->y; rect.w = lb->trans_area->w; rect.h = lb->trans_area->h; blit_surface(lb->trans_area, NULL, &rect, 0); } if (lb->num_items == 0) return; /* now draw the items */ /* set "item" to the first item for the top, as dedicated by the progress bar */ item = (int)((float)lb->sb->progress * (float)(lb->num_items - 1)); lb->top_scrolled = item; /* draw the top bar */ rect.x = lb->x; rect.y = lb->y; rect.w = lb->w - 17; rect.h = 2; fill_rect(&rect, map_rgb(0, 93, 92)); /* draw all the item borders and call the callback (if one exists) to draw what's inside each element */ for (i = 0; (item < lb->num_items) && ((i * lb->item_h) < lb->h); i++) { if ((i + lb->top_scrolled) == lb->selected) { /* draw the selected bg */ rect.x = lb->x; rect.y = lb->y + (i * lb->item_h) + 2; rect.w = lb->w - 17; rect.h = lb->item_h - 2; if ((rect.y + rect.h) > (lb->y + lb->h)) rect.h = (lb->y + lb->h) - rect.y; fill_rect(&rect, map_rgb(0, 64, 65)); } /* draw the bottom item bar */ rect.x = lb->x; rect.y = lb->y + (i * lb->item_h) + lb->item_h; rect.w = lb->w - 17; rect.h = 2; if (rect.y < (lb->y + lb->h)) fill_rect(&rect, map_rgb(0, 93, 92)); if (lb->callback) (*lb->callback) (lb, rect.x, rect.y - lb->item_h, rect.w, lb->item_h, item); item++; } }
/** *\fn int main(int argc, char *argv[]) * Main *\param[in,out] argc argc *\param[in,out] argv argv */ int main(int argc, char *argv[]) { SDL_Surface *screen = NULL; int go = 1; int ret,ret1, ret2 = 0, ret3, ret4; char level_name[MAX_SIZE_FILE_NAME]; char player_name[MAX_SIZE_FILE_NAME]; int nb_lvl; /*sound*/ Sound *sound_system; sound_system = createSound(); /*keyboard config*/ SDLKey kc[NB_KEY-1]; /*input*/ Input in; SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK); Player *current_player; current_player = (Player *)malloc(sizeof(Player)); /*screen initialization*/ screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); initInput(&in); /*configurations loading */ loadSoundOptions("configuration/sound.conf",sound_system); SDL_WM_SetCaption("Super Martin", NULL); //window name SDL_ShowCursor(SDL_DISABLE); //delete the mouse while (go) //main loop { if(titleMenu(screen,&go,sound_system, &in)) { while( (ret3 = menuPlayers(screen, player_name, &go, sound_system, &in)) != -1 && go) { switch(ret3) { case -1: break; case 2 : ret2 = newPlayer(screen, player_name, sound_system, &go); if(ret2 == 1) { current_player->levelMax = 1; current_player->nbCoins = 0; current_player->nbLifes = 3; current_player->nbProjectile = 5; savePlayer("save/.save", player_name, current_player); loadInputOptions("default",kc,&in); saveInputOptions(player_name, kc, &in); } else break; case 1 : loadPlayer("save/.save", player_name, current_player); loadInputOptions(player_name,kc,&in); while(go && (ret1 = mainMenu(screen,&go,sound_system, player_name, &in)) != -1) { switch(ret1) { case -1: break; case 0: while( (ret4 = menuLevel(screen,level_name,sound_system, player_name, current_player, &go, &nb_lvl, &in)) != -1 && go) { while(play(screen,level_name,sound_system,&go,kc, &in, current_player, player_name, ret4+1, nb_lvl) && go); } break; case 1 : save(screen, "save/.save", player_name, current_player, &go); loadPlayer("save/.save", player_name, current_player); break; case 2 : while((ret = optionMenu(screen,&go,sound_system,kc, &in)) != -1 && go) { switch(ret) { case -1: break; case 0: soundOptions(screen,&go,sound_system, &in); break; case 1: keyBoardOptions(screen,&go,kc,&in,player_name); break; default:; } } break; case 3 : deletePlayer(screen, "save/players", player_name); go = 0; break; default: ; } } go = 1; break; default : ; } } } SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,255,255,255)); //clear screen SDL_Flip(screen); } freeSound(sound_system); free((void*)current_player); freeInput(&in); SDL_Quit(); return EXIT_SUCCESS; }
/** * Highlight selected row in the party list. * @param list * List. * @param box * Dimensions for the row. */ static void list_row_selected(list_struct *list, SDL_Rect box) { SDL_FillRect(list->surface, &box, SDL_MapRGB(list->surface->format, 0x00, 0x00, 0xef)); }
/** * Highlight a row in the party list. * @param list * List. * @param box * Dimensions for the row. */ static void list_row_highlight(list_struct *list, SDL_Rect box) { SDL_FillRect(list->surface, &box, SDL_MapRGB(list->surface->format, 0x00, 0x80, 0x00)); }
int main ( int argc, char** argv ) { if(init() == false) { return 1; } //set up player SDL_Surface* faceman; if(!(loadSurface("res/img/faceman.png", &faceman))) { return 1; } /* * Player Declarations */ Identifier::Identifier ider; Point dirVect; Point start; Point dimensions; double terminalVelocity; Point acceleration; /* * Player Assignments */ start.x = 20; start.y = 20; dimensions.x = 32; dimensions.y = 32; acceleration.x = .05; acceleration.y = .05; terminalVelocity = 0.15; /* * Player declaration/initialization */ Faceman::Faceman player(faceman,start,acceleration,dimensions,terminalVelocity, ider); SDL_Rect playerPos; //set clock offset SDL_Rect clockoff; clockoff.x=5; clockoff.y=5; //load font TTF_Font *font = TTF_OpenFont("BankGothicLightBT.ttf", 24); //initialize time values: Uint32 startTime = SDL_GetTicks(); Uint32 currentTime = startTime; Uint32 timePassed = 0; Uint32 clockTime = 0; SDL_Surface* displayTime; // Main Game Loop bool done = false; while (!done) { //update time values: timePassed = SDL_GetTicks() - currentTime; currentTime = SDL_GetTicks(); clockTime = currentTime - startTime; displayTime = timeToSurface(clockTime, font); // message processing loop SDL_Event event; while (SDL_PollEvent(&event)) { // check for messages switch (event.type) { // exit if the window is closed case SDL_QUIT: done = true; break; // check for keypresses case SDL_KEYDOWN: { keyDown[event.key.keysym.sym] = true; } break; case SDL_KEYUP: { keyDown[event.key.keysym.sym] = false; } break; } // end switch } // end of message processing // MOVEMENT CALC/UPDATE STARTS HERE done = keyDown[SDLK_ESCAPE]; //check if done // initialize/reset directional vector struct dirVect.x = 0; dirVect.y = 0; /* * Check for player input */ if(keyDown[SDLK_w] == true){dirVect.y = -1;} if(keyDown[SDLK_s] == true){dirVect.y = dirVect.y + 1;} if(keyDown[SDLK_a] == true){dirVect.x = -1;} if(keyDown[SDLK_d] == true){dirVect.x = dirVect.x + 1;} playerPos = player.move(dirVect, timePassed); // DRAWING STARTS HERE // clear screen SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); // draw images SDL_BlitSurface(player.m_img,0,screen,&playerPos); // apply clock SDL_BlitSurface(displayTime,0, screen, &clockoff); // DRAWING ENDS HERE // finally, update the screen :) SDL_Flip(screen); //delay SDL_Delay(REFRESHMENT_DELAY); } // end main loop // free loaded img SDL_FreeSurface(player.m_img); //Close the font TTF_CloseFont( font ); //Quit SDL_ttf TTF_Quit(); // all is well ;) printf("Exited cleanly\n"); return 0; }
bool ChooseAnImage(int sx,int sy, char *incoming_dir, int slot, char **filename, bool *isdir, int *index_file) { /* Parameters: sx, sy - window size, incoming_dir - in what dir find files, slot - in what slot should an image go (common: #6 for 5.25' 140Kb floppy disks, and #7 for hard-disks). slot #5 - for 800Kb floppy disks, but we do not use them in Apple][? (They are as a rule with .2mg extension) index_file - from which file we should start cursor (should be static and 0 when changing dir) Out: filename - chosen file name (or dir name) isdir - if chosen name is a directory */ /* Surface: */ SDL_Surface *my_screen; // for background if(font_sfc == NULL) if(!fonts_initialization()) return false; //if we don't have a fonts, we just can do none List<char> files; // our files List<char> sizes; // and their sizes (or 'dir' for directories) int act_file; // current file int first_file; // from which we output files printf("Disckchoose! We are here: %s\n",incoming_dir); // files.Delete(); // sizes.Delete(); #ifndef _WIN32 /* POSIX specific routines of reading directory structure */ DIR *dp; struct dirent *ep; dp = opendir (incoming_dir); // open and read incoming directory char *tmp; int i,j, B, N; // for cycles, beginning and end of list // build prev dir if(strcmp(incoming_dir, "/")) { tmp = new char[3]; strcpy(tmp, ".."); files.Add(tmp); tmp = new char[5]; strcpy(tmp, "<UP>"); sizes.Add(tmp); // add sign of directory B = 1; } else B = 0; // for sorting dirs if (dp != NULL) { while (ep = readdir (dp)) // first looking for directories { int what = getstat(incoming_dir, ep->d_name, NULL); if (strlen(ep->d_name) > 0 && /*strcmp(ep->d_name,".")*/// omit "." (cur dir) ep->d_name[0] != '.'/*strcmp(ep->d_name,"..")*/ && what == 1) // is directory! { tmp = new char[strlen(ep->d_name)+1]; // add entity to list strcpy(tmp, ep->d_name); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } /* if */ } } #else /* Windows specific functions of reading directory structure */ /* Find subdirs: */ if(strcmp(incoming_dir, "/")) { // we are not in upper direcory tmp = new char[3]; strcpy(tmp, ".."); files.Add(tmp); tmp = new char[5]; strcpy(tmp, "<UP>"); sizes.Add(tmp); // add sign of directory B = 1; } else B = 0; // for sorting dirs WIN32_FIND_DATA finfo; HANDLE h; h=FindFirstFile(incoming_dir,&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0) { // add this entry if it is directory tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } while(FindNextFile(h,&finfo)==TRUE) { if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0) { // add this entry if it is directory tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } } /* while */ } /* if */ #endif // sort directories. Please, don't laugh at my bubble sorting - it the simplest thing I've ever seen --bb if(files.Length() > 2) { N = files.Length() - 1; // B = 1;`- defined above for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } B = files.Length(); // start for files #ifndef _WIN32 /* POSIX specific routines of reading directory structure */ (void) rewinddir (dp); // to the start // now get all regular files while (ep = readdir (dp)) { int fsize; if (strlen(ep->d_name) > 4 && ep->d_name[0] != '.' && (getstat(incoming_dir, ep->d_name, &fsize) == 2)) // is normal file! { tmp = new char[strlen(ep->d_name)+1]; // add this entity to list strcpy(tmp, ep->d_name); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", fsize); sizes.Add(tmp); // add this size to list } /* if */ } (void) closedir (dp); #else /* Windows specific functions of reading directory structure */ /* Find files: */ h=FindFirstFile(incoming_dir,&finfo); if (h!=INVALID_HANDLE_VALUE) { // char *tmp; - must be defined in previous section, when searching subdirs if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == 0) { // add this entry if it is NOT directory! tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", ((finfo.nFileSizeHigh * (MAXDWORD+1)) + finfo.nFileSizeLow)); sizes.Add(tmp); // add this size to list } while(FindNextFile(h,&finfo)==TRUE) { if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == 0) { // add this entry if it is NOT directory! tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", ((finfo.nFileSizeHigh * (MAXDWORD+1)) + finfo.nFileSizeLow)); sizes.Add(tmp); // add this size to list } } /* while */ } /* if */ #endif // do sorting for files if(files.Length() > 2 && B < files.Length()) { N = files.Length() - 1; // B = 1; for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } // Count out cursor position and file number output act_file = *index_file; if(act_file >= files.Length()) act_file = 0; // cannot be more than files in list first_file = act_file - (FILES_IN_SCREEN / 2); if (first_file < 0) first_file = 0; // cannot be negativ... // Show all directories (first) and files then // char *tmp; char *siz; // int i; // prepare screen double facx = double(g_ScreenWidth) / double(SCREEN_WIDTH); double facy = double(g_ScreenHeight) / double(SCREEN_HEIGHT); SDL_Surface *tempSurface = NULL; if(!g_WindowResized) { if(g_nAppMode == MODE_LOGO) tempSurface = g_hLogoBitmap; // use logobitmap else tempSurface = g_hDeviceBitmap; } else tempSurface = g_origscreen; if(tempSurface == NULL) tempSurface = screen; // use screen, if none available my_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, tempSurface->w, tempSurface->h, tempSurface->format->BitsPerPixel, 0, 0, 0, 0); if(tempSurface->format->palette && my_screen->format->palette) SDL_SetColors(my_screen, tempSurface->format->palette->colors, 0, tempSurface->format->palette->ncolors); surface_fader(my_screen, 0.2F, 0.2F, 0.2F, -1, 0); // fade it out to 20% of normal SDL_BlitSurface(tempSurface, NULL, my_screen, NULL); while(true) { SDL_BlitSurface(my_screen, NULL, screen, NULL); // show background font_print_centered(sx/2 ,5*facy , incoming_dir, screen, 1.5*facx, 1.3*facy); if (slot == 6) font_print_centered(sx/2,20*facy,"Choose image for floppy 140KB drive", screen, 1*facx, 1*facy); else if (slot == 7) font_print_centered(sx/2,20*facy,"Choose image for Hard Disk", screen, 1*facx, 1*facy); else if (slot == 5) font_print_centered(sx/2,20*facy,"Choose image for floppy 800KB drive", screen, 1*facx, 1*facy); else if (slot == 1) font_print_centered(sx/2,20*facy,"Select file name for saving snapshot", screen, 1*facx, 1*facy); else if (slot == 0) font_print_centered(sx/2,20*facy,"Select snapshot file name for loading", screen, 1*facx, 1*facy); font_print_centered(sx/2,30*facy, "Press ENTER to choose, or ESC to cancel",screen, 1.4*facx, 1.1*facy); files.Rewind(); // from start sizes.Rewind(); i = 0; // printf("We've printed some messages, go to file list!\n"); // show all fetched dirs and files // topX of first fiel visible int TOPX = int(45*facy); while(files.Iterate(tmp)) { sizes.Iterate(siz); // also fetch size string if (i >= first_file && i < first_file + FILES_IN_SCREEN) { // FILES_IN_SCREEN items on screen // char tmp2[80],tmp3[256]; if (i == act_file) { // show item under cursor (in inverse mode) SDL_Rect r; r.x= 2; r.y= TOPX + (i-first_file) * 15 * facy - 1; if(strlen(tmp) > 46) r.w = 46 * FONT_SIZE_X /* 6 */ * 1.7 * facx + 2; else r.w= strlen(tmp) * FONT_SIZE_X /* 6 */ * 1.7 * facx + 2; // 6- FONT_SIZE_X r.h= 9 * 1.5 * facy; SDL_FillRect(screen, &r, SDL_MapRGB(screen->format,255,0,0));// in RED } /* if */ // print file name with enlarged font char ch; ch = 0; if(strlen(tmp) > 46) { ch = tmp[46]; tmp[46] = 0;} //cut-off too long string font_print(4, TOPX + (i - first_file) * 15 * facy, tmp, screen, 1.7*facx, 1.5*facy); // show name font_print(sx - 70 * facx, TOPX + (i - first_file) * 15 * facy, siz, screen, 1.7*facx, 1.5*facy);// show info (dir or size) if(ch) tmp[46] = ch; //restore cut-off char } /* if */ i++; // next item } /* while */ ///////////////////////////////////////////////////////////////////////////////////////////// // draw rectangles rectangle(screen, 0, TOPX - 5, sx, 320*facy, SDL_MapRGB(screen->format, 255, 255, 255)); rectangle(screen, 480*facx, TOPX - 5, 0, 320*facy, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_Flip(screen); // show the screen SDL_Delay(KEY_DELAY); // wait some time to be not too fast ////////////////////////////////// // Wait for keypress ////////////////////////////////// SDL_Event event; // event Uint8 *keyboard; // key state event.type = SDL_QUIT; while(event.type != SDL_KEYDOWN) { // wait for key pressed SDL_Delay(10); SDL_PollEvent(&event); } // control cursor keyboard = SDL_GetKeyState(NULL); // get current state of pressed (and not pressed) keys if (keyboard[SDLK_UP] || keyboard[SDLK_LEFT]) { if (act_file>0) act_file--; // up one position if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_DOWN] || keyboard[SDLK_RIGHT]) { if (act_file < (files.Length() - 1)) act_file++; if (act_file >= (first_file + FILES_IN_SCREEN)) first_file=act_file - FILES_IN_SCREEN + 1; } /* if */ if (keyboard[SDLK_PAGEUP]) { act_file-=FILES_IN_SCREEN; if (act_file<0) act_file=0; if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_PAGEDOWN]) { act_file+=FILES_IN_SCREEN; if (act_file>=files.Length()) act_file=(files.Length()-1); if (act_file>=(first_file+FILES_IN_SCREEN)) first_file=act_file-FILES_IN_SCREEN + 1; } /* if */ // choose an item? if (keyboard[SDLK_RETURN]) { // dup string from selected file name *filename = strdup(files[act_file]); // printf("files[act_file]=%s, *filename=%s\n\n", files[act_file], *filename); if(!strcmp(sizes[act_file], "<DIR>") || !strcmp(sizes[act_file], "<UP>")) *isdir = true; else *isdir = false; // this is directory (catalog in Apple][ terminology) *index_file = act_file; // remember current index files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return true; } /* if */ if (keyboard[SDLK_ESCAPE]) { files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return false; // ESC has been pressed } /* if */ if (keyboard[SDLK_HOME]) { // HOME? act_file=0; first_file=0; } /* if */ if (keyboard[SDLK_END]) { // END? act_file=files.Length() - 1; // go to the last possible file in list first_file=act_file - FILES_IN_SCREEN + 1; if(first_file < 0) first_file = 0; } /* if */ } } /* ChooseAnImage */
int main(void) { SDL_Event e; SDL_Rect rect = {10, 10, 50, 50}; SDL_Rect imgrect = {0, 0, IMG_W, IMG_H}; SDL_Surface *img = SDL_LoadBMP("test.bmp"); SDL_Surface *w = SDL_SetVideoMode(WIN_W, WIN_H, 0, SDL_HWSURFACE | SDL_DOUBLEBUF); int quit = 0; /* Initialize SDL and make sure it quits*/ if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("ERROR: unable to init SDL: %s\n", SDL_GetError()); return 1; } atexit(SDL_Quit); /* Create window surface*/ if (w == NULL) { printf("ERROR: failed to set video mode: %s\n", SDL_GetError()); return 1; } /* Define the rects we need*/ /* Load test spritesheet image*/ if (img == NULL) { printf("ERROR: failed to load image: %s\n", SDL_GetError()); return 1; } /* Set colorkey to BLUE*/ if (SDL_SetColorKey(img, SDL_SRCCOLORKEY, SDL_MapRGB(img->format, 0, 0, 255)) != 0) { printf("ERROR: failed to set color key: %s\n", SDL_GetError()); SDL_FreeSurface(img); return 1; } while (!quit) { /* Clear window to BLACK*/ if (SDL_FillRect(w,0,0) != 0) { printf("ERROR: failed to draw rect: %s\n", SDL_GetError()); break; } /* Green rectangle button*/ if (SDL_FillRect(w, &rect, SDL_MapRGB(w->format, 0, 255, 0)) != 0) { printf("ERROR: failed to draw rect: %s\n", SDL_GetError()); break; } /* Draw image sprite*/ if (SDL_BlitSurface(img, &imgrect, w, 0) != 0) { SDL_FreeSurface(img); printf("ERROR: failed to blit image: %s\n", SDL_GetError()); break; } /* Advance to next sprite*/ imgrect.x += imgrect.w; if (imgrect.x >= img->w) { imgrect.x = 0; imgrect.y += imgrect.h; if (imgrect.y >= img->h) imgrect.y = 0; } /* We finished drawing*/ if (SDL_Flip(w) != 0) { printf("ERROR: failed to flip buffer: %s\n", SDL_GetError()); break; } /* Poll for keyboard & mouse events*/ while (SDL_PollEvent(&e) != 0) { switch (e.type) { case (SDL_QUIT): quit = 1; break; case (SDL_KEYUP): if (e.key.keysym.sym == SDLK_ESCAPE) quit = 1; break; case (SDL_MOUSEBUTTONUP): if ((e.button.x > rect.x) && (e.button.x < rect.x + rect.w) && (e.button.y > rect.y) && (e.button.y < rect.y+rect.h)) quit = 1; break; default: break; } } /* Wait a little before redrawing*/ SDL_Delay(1000); } SDL_FreeSurface(img); return 0; }
void view::Surface::setSurface(SDL_Surface* newSurface) { SDL_Surface* aux = SDL_DisplayFormat(newSurface); SDL_SetColorKey(aux,SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB(aux->format,255,0,255)); this->surface = aux; }
int main( int argc, char* args[] ) { //Quit flag bool quit = false; //Initialize if( init() == false ) { return 1; } //Load the files if( load_files() == false ) { return 1; } //Clip the sprite sheet set_clips(); //The frame rate regulator Timer fps; //The stick figure Foo walk; //While the user hasn't quit while( quit == false ) { //Start the frame timer fps.start(); //While there's events to handle while( SDL_PollEvent( &event ) ) { //Handle events for the stick figure walk.handle_events(); //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Move the stick figure walk.move(); //Fill the screen white SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) ); //Show the stick figure on the screen walk.show(); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } //Clean up clean_up(); return 0; }
void view::Surface::addShadowSurface(SDL_Surface* surface) { SDL_Surface* aux = SDL_DisplayFormat(surface); //this->shadow = SDL_DisplayFormat(surface); SDL_SetColorKey(aux, SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB(aux->format, 255, 0, 255)); this->shadows.push_back(aux); }
SubImageFont::SubImageFont(const std::string& filename, const std::string& glyphs) : ImageFontBase() { FL_LOG(_log, LMsg("fifechan_image_font, loading ") << filename << " glyphs " << glyphs); ImagePtr img = ImageManager::instance()->load(filename); SDL_Surface* surface = img->getSurface(); m_colorkey = RenderBackend::instance()->getColorKey(); if( !surface ) { throw CannotOpenFile(filename); } // Make sure we get 32bit RGB // and copy the Pixelbuffers surface SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w,surface->h,32, RMASK, GMASK, BMASK ,NULLMASK); SDL_BlitSurface(surface,0,tmp,0); surface = tmp; // Prepare the data for extracting the glyphs. uint32_t *pixels = reinterpret_cast<uint32_t*>(surface->pixels); int32_t x = 0; SDL_Rect src; src.h = surface->h; src.y = 0; uint32_t separator = pixels[0]; uint32_t colorkey = SDL_MapRGB(surface->format, m_colorkey.r, m_colorkey.g, m_colorkey.b); // if colorkey feature is not enabled then manually find the color key in the font if (!RenderBackend::instance()->isColorKeyEnabled()) { while(x < surface->w && pixels[x] == separator) { ++x; } colorkey = pixels[x]; } // Disable alpha blending, so that we use color keying SDL_SetAlpha(surface,0,255); SDL_SetColorKey(surface,SDL_SRCCOLORKEY,colorkey); FL_DBG(_log, LMsg("image_font") << " glyph separator is " << pprint(reinterpret_cast<void*>(separator)) << " transparent color is " << pprint(reinterpret_cast<void*>(colorkey))); // Finally extract all glyphs std::string::const_iterator text_it = glyphs.begin(); while(text_it != glyphs.end()) { int32_t w = 0; while(x < surface->w && pixels[x] == separator) ++x; if( x == surface->w ) break; while(x + w < surface->w && pixels[x + w] != separator) ++w; src.x = x; src.w = w; tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, w,surface->h,32, RMASK, GMASK, BMASK ,NULLMASK); SDL_FillRect(tmp,0,colorkey); SDL_BlitSurface(surface,&src,tmp,0); // Disable alpha blending, so that we use colorkeying SDL_SetAlpha(tmp,0,255); SDL_SetColorKey(tmp,SDL_SRCCOLORKEY,colorkey); uint32_t codepoint = utf8::next(text_it, glyphs.end()); m_glyphs[ codepoint ].surface = tmp; x += w; } // Set placeholder glyph // This should actually work ith utf8. if( m_glyphs.find('?') != m_glyphs.end() ) { m_placeholder = m_glyphs['?']; } else { m_placeholder.surface = 0; } m_height = surface->h; SDL_FreeSurface(surface); }
void SystemStub_SDL::setPaletteEntry(uint8 i, const Color *c) { uint8 r = (c->r << 2) | (c->r & 3); uint8 g = (c->g << 2) | (c->g & 3); uint8 b = (c->b << 2) | (c->b & 3); _pal[i] = SDL_MapRGB(_screen->format, r, g, b); }
int main(int argc, char *argv[]) { SDL_Event event; SDL_Rect position; int continuer = 1; if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1) { printf("%s", Mix_GetError()); } TTF_Init(); if(TTF_Init() == -1) { fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError());/*S'il y a eu une erreur au démarrage de SDL_ttf, un fichier stderr.txt sera créé contenant un message explicatif de l'erreur.la fonction TTF_GetError() renvoie le dernier message d'erreur de SDL_ttf.C'est pour cela qu'on l'utilise dans le fprintf.*/ exit(EXIT_FAILURE); } // initialize SDL video if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { printf( "Unable to init SDL: %s\n", SDL_GetError() ); return 1; } // make sure SDL cleans up before exit atexit(SDL_Quit); // create a new window SDL_Surface *ecran = SDL_SetVideoMode(1150,750,32,SDL_HWSURFACE | SDL_DOUBLEBUF);//602,402 if ( !ecran ) { printf("Unable to set 602x402 video: %s\n", SDL_GetError()); return 1; } SDL_WM_SetCaption("Menu de jeu TIC TAC TOE", NULL); // load an image SDL_Surface* bmp = SDL_LoadBMP("images/morpion.bmp"); if (!bmp) { printf("Unable to load bitmap: %s\n", SDL_GetError()); return 1; } // centre the bitmap on screen SDL_Rect font; font.x = (ecran->w-bmp->w) / 2; font.y = (ecran->h-bmp->h) / 2; Musiques m; Mix_AllocateChannels(2); m.musique= Mix_LoadMUS("musiques/musique1.mp3"); m.Clic= Mix_LoadWAV("musiques/clic1.wav"); Mix_VolumeMusic(200); Mix_PlayMusic(m.musique,-1); Mix_PlayChannel(0,m.Clic,0); while (continuer) { SDL_WaitEvent(&event); switch(event.type) { case SDL_QUIT: continuer = 0; break; case SDL_MOUSEBUTTONDOWN: position.x = event.motion.x ; position.y = event.motion.y ; break; case SDL_KEYUP: if(event.key.keysym.sym==SDLK_s) continuer= 0; break; } // clear screen SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format,0,0,0)); // draw bitmap SDL_BlitSurface(bmp,0,ecran,&font); SDL_Flip(ecran); MenuPrincipal(); } Mix_FreeMusic(m.musique); Mix_FreeChunk(m.Clic); Mix_CloseAudio(); TTF_Quit(); SDL_Quit(); return EXIT_SUCCESS; }
void CSDL_Ext::fillRectBlack( SDL_Surface *dst, SDL_Rect *dstrect) { const Uint32 black = SDL_MapRGB(dst->format,0,0,0); fillRect(dst,dstrect,black); }
void DebugStage::Render() { int elevation = 24; spResetZBuffer(); spIdentity(); spClearTarget(SDL_MapRGB( display->format, 190, 190, 220 )); spSetLight(1); spSetCulling(1); spSetZSet(1); spSetZTest(1); spSetAlphaTest(1); Sint32 brightness = 65535; // (spCos(rotation+a*SP_PI/8)>>SP_HALF_ACCURACY)*abs(spCos(rotation+a*SP_PI/8)>>SP_HALF_ACCURACY)/2+(3<<SP_ACCURACY-1); Uint16 color = 0x8410; // 0xFFFF; // ((brightness>>SP_ACCURACY-4)<<11)+((brightness>>SP_ACCURACY-5)<<5)+(brightness>>SP_ACCURACY-4); spTranslate(0,-6<<SP_ACCURACY,-24<<SP_ACCURACY); spRotateX(rotation); for( int a = 0; a < 64; a++ ) { spRotateX(SP_PI/32); if( ((rotation / (SP_PI/32)) + a) % 64 > 32 ) { int yA, yB; ////////////////////////////////////////// Left OffRoad yA = -15; // + LeftWall[a+1]; yB = -15 + LeftWall[a]; if( yA > yB ) { int yT = yB; yB = yA; yA = yT; } elevation = 25; spBindTexture(roadsideTexture); if( ((rotation / (SP_PI/32)) + a) % 64 > 56 ) { spQuadTex3D(((4*yA)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*yA)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,1,roadsideTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,roadsideTexture->w-SP_FONT_EXTRASPACE-1,roadsideTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,roadsideTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); } yA = -15 + LeftWall[(a+1) % 64] + 1; if( LeftWall[a+1] != LeftWall[a] ) { spQuadTex3D(((4*yA)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*yA)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,1,roadsideTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,roadsideTexture->w-SP_FONT_EXTRASPACE-1,roadsideTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,roadsideTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); } spQuadTex3D(((4*yB)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*yB)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); yA = -15; // + LeftWall[a+1]; spBindTexture(offroadTexture); spQuadTex3D(((4*yA)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*yA)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); ////////////////////////////////////////// Right OffRoad yA = 15 - RightWall[a]; yB = 15; if( yA > yB ) { int yT = yB; yB = yA; yA = yT; } elevation = 25; spBindTexture(roadsideTexture); if( ((rotation / (SP_PI/32)) + a) % 64 > 56 ) { spQuadTex3D(((4*yA)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*yA)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,1,roadsideTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,roadsideTexture->w-SP_FONT_EXTRASPACE-1,roadsideTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,roadsideTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); } yB = 15 - RightWall[(a+1) % 64] - 1; if( RightWall[a+1] != RightWall[a] ) { spQuadTex3D(((4*yA)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*yA)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,1,roadsideTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,roadsideTexture->w-SP_FONT_EXTRASPACE-1,roadsideTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,roadsideTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); } spQuadTex3D(((4*yA)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*yA)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,1,roadsideTexture->h-SP_FONT_EXTRASPACE-1, ((4*yA)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,roadsideTexture->w-SP_FONT_EXTRASPACE-1,roadsideTexture->h-SP_FONT_EXTRASPACE-1, ((4*yA)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,roadsideTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); yB = 15; // + LeftWall[a+1]; spBindTexture(offroadTexture); spQuadTex3D(((4*yA)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*yA)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); // Draw Road yA = -14 + LeftWall[a]; yB = 14 - RightWall[a]; spBindTexture(roadTexture); elevation = 24; spQuadTex3D(((4*yA)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*yA)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,1,roadTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,roadTexture->w-SP_FONT_EXTRASPACE-1,roadTexture->h-SP_FONT_EXTRASPACE-1, ((4*yB)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,roadTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); /* for( int y = -15; y <= 15; y++ ) { if( y <= -15 + LeftWall[a] || y >= 15 - RightWall[a] ) { elevation = 25; //if( ((rotation / (SP_PI/32)) + a) % 64 == 60 && y == carPos ) // spBindTexture(carTexture); //else spBindTexture(roadsideTexture); if( ((rotation / (SP_PI/32)) + a) % 64 > 56 ) { spQuadTex3D(((4*y)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*y)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); } if( y == -15 + LeftWall[a] || y == 15 - RightWall[a] ) { if( (y == -15 + LeftWall[a] && LeftWall[a] > LeftWall[a+1]) || (y == 15 - RightWall[a] && RightWall[a] > RightWall[a+1]) ) { spQuadTex3D(((4*y)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*y)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); } spQuadTex3D(((4*y)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*y)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); spQuadTex3D(((4*y)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*y)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, (elevation-1)<<SP_ACCURACY-1,1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); } spBindTexture(offroadTexture); spQuadTex3D(((4*y)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*y)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); } else { //if( ((rotation / (SP_PI/32)) + a) % 64 == 60 && y == carPos ) // spBindTexture(carTexture); //else spBindTexture(roadTexture); elevation = 24; spQuadTex3D(((4*y)-2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,SP_FONT_EXTRASPACE,SP_FONT_EXTRASPACE, ((4*y)-2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)+2)<<SP_ACCURACY-2,-3<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,offroadTexture->h-SP_FONT_EXTRASPACE-1, ((4*y)+2)<<SP_ACCURACY-2,+2<<SP_ACCURACY-2, elevation<<SP_ACCURACY-1,offroadTexture->w-SP_FONT_EXTRASPACE-1,SP_FONT_EXTRASPACE,color); } } */ } } spIdentity(); spBindTexture(carTexture); spTranslate( carGfxAt, -3<<SP_ACCURACY, -12<<SP_ACCURACY ); spRotateY( (SP_PI/8)*12 ); spRotateZ( (SP_PI/16)*26 ); if( crashed != 0 ) { spRotateX( (SP_PI/16)*(crashTick < 6 ? crashTick : 6) ); spRotateY( (SP_PI/16)*crashTick ); spRotateZ( (SP_PI/16)*crashTick ); char crashText[80]; int crashYAdj; if( crashHiScore >= 0 ) { sprintf((char*)&crashText, "Well Done\nNew High Score\nRank %d", (crashHiScore+1) ); crashYAdj = (int)((double)fontHiSHnd->maxheight * 1.5); } else { sprintf((char*)&crashText, "Game Over" ); crashYAdj = (int)(fontHiSHnd->maxheight / 2); } spSetZSet( 0 ); spSetZTest( 0 ); spFontDrawMiddle( (gameSettings->ScreenWidth / 2) + 4, (gameSettings->ScreenHeight / 2) + 4 - crashYAdj, -1, (char*)&crashText, fontHiSHnd ); spFontDrawMiddle( (gameSettings->ScreenWidth / 2), (gameSettings->ScreenHeight / 2) - crashYAdj, -1, (char*)&crashText, fontHiHnd ); spSetZSet( 1 ); spSetZTest( 1 ); } else if( carGfxTo > carGfxAt ) { spRotateY( -(SP_PI/16) ); } else if( carGfxTo < carGfxAt ) { spRotateY( (SP_PI/16) ); } spMesh3D( carMesh, 0 ); char scoreText[15]; sprintf((char*)&scoreText, "Score: %d", (int)(score > 9999999 ? 9999999 : score) ); spFontDraw( 10, 10, -1, (char*)&scoreText, fontHnd ); }
SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src) { int start; const char *error; SDL_Surface *volatile surface; png_structp png_ptr; png_infop info_ptr; png_uint_32 width, height; int bit_depth, color_type, interlace_type, num_channels; Uint32 Rmask; Uint32 Gmask; Uint32 Bmask; Uint32 Amask; SDL_Palette *palette; png_bytep *volatile row_pointers; int row, i; volatile int ckey = -1; png_color_16 *transv; if ( !src ) { /* The error message has been set in SDL_RWFromFile */ return NULL; } start = SDL_RWtell(src); if ( !IMG_Init(IMG_INIT_PNG) ) { return NULL; } /* Initialize the data we will clean up when we're done */ error = NULL; png_ptr = NULL; info_ptr = NULL; row_pointers = NULL; surface = NULL; /* Create the PNG loading context structure */ png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,NULL,NULL); if (png_ptr == NULL){ error = "Couldn't allocate memory for PNG file or incompatible PNG dll"; goto done; } /* Allocate/initialize the memory for image information. REQUIRED. */ info_ptr = lib.png_create_info_struct(png_ptr); if (info_ptr == NULL) { error = "Couldn't create image information for PNG file"; goto done; } /* Set error handling if you are using setjmp/longjmp method (this is * the normal method of doing things with libpng). REQUIRED unless you * set up your own error handlers in png_create_read_struct() earlier. */ #ifndef LIBPNG_VERSION_12 if ( setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof (jmp_buf))) ) #else if ( setjmp(png_ptr->jmpbuf) ) #endif { error = "Error reading the PNG file."; goto done; } /* Set up the input control */ lib.png_set_read_fn(png_ptr, src, png_read_data); /* Read PNG header info */ lib.png_read_info(png_ptr, info_ptr); lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL); /* tell libpng to strip 16 bit/color files down to 8 bits/color */ lib.png_set_strip_16(png_ptr) ; /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single * byte into separate bytes (useful for paletted and grayscale images). */ lib.png_set_packing(png_ptr); /* scale greyscale values to the range 0..255 */ if(color_type == PNG_COLOR_TYPE_GRAY) lib.png_set_expand(png_ptr); /* For images with a single "transparent colour", set colour key; if more than one index has transparency, or if partially transparent entries exist, use full alpha channel */ if (lib.png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { int num_trans; Uint8 *trans; lib.png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &transv); if(color_type == PNG_COLOR_TYPE_PALETTE) { /* Check if all tRNS entries are opaque except one */ int i, t = -1; for(i = 0; i < num_trans; i++) if(trans[i] == 0) { if(t >= 0) break; t = i; } else if(trans[i] != 255) break; if(i == num_trans) { /* exactly one transparent index */ ckey = t; } else { /* more than one transparent index, or translucency */ lib.png_set_expand(png_ptr); } } else ckey = 0; /* actual value will be set later */ } if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA ) lib.png_set_gray_to_rgb(png_ptr); lib.png_read_update_info(png_ptr, info_ptr); lib.png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL); /* Allocate the SDL surface to hold the image */ Rmask = Gmask = Bmask = Amask = 0 ; num_channels = lib.png_get_channels(png_ptr, info_ptr); if ( color_type != PNG_COLOR_TYPE_PALETTE ) { if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) { Rmask = 0x000000FF; Gmask = 0x0000FF00; Bmask = 0x00FF0000; Amask = (num_channels == 4) ? 0xFF000000 : 0; } else { int s = (num_channels == 4) ? 0 : 8; Rmask = 0xFF000000 >> s; Gmask = 0x00FF0000 >> s; Bmask = 0x0000FF00 >> s; Amask = 0x000000FF >> s; } } surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, bit_depth*num_channels, Rmask,Gmask,Bmask,Amask); if ( surface == NULL ) { error = "Out of memory"; goto done; } if(ckey != -1) { if(color_type != PNG_COLOR_TYPE_PALETTE) /* FIXME: Should these be truncated or shifted down? */ ckey = SDL_MapRGB(surface->format, (Uint8)transv->red, (Uint8)transv->green, (Uint8)transv->blue); SDL_SetColorKey(surface, SDL_SRCCOLORKEY, ckey); } /* Create the array of pointers to image data */ row_pointers = (png_bytep*) malloc(sizeof(png_bytep)*height); if ( (row_pointers == NULL) ) { error = "Out of memory"; goto done; } for (row = 0; row < (int)height; row++) { row_pointers[row] = (png_bytep) (Uint8 *)surface->pixels + row*surface->pitch; } /* Read the entire image in one go */ lib.png_read_image(png_ptr, row_pointers); /* and we're done! (png_read_end() can be omitted if no processing of * post-IDAT text/time/etc. is desired) * In some cases it can't read PNG's created by some popular programs (ACDSEE), * we do not want to process comments, so we omit png_read_end lib.png_read_end(png_ptr, info_ptr); */ /* Load the palette, if any */ palette = surface->format->palette; if ( palette ) { int png_num_palette; png_colorp png_palette; lib.png_get_PLTE(png_ptr, info_ptr, &png_palette, &png_num_palette); if(color_type == PNG_COLOR_TYPE_GRAY) { palette->ncolors = 256; for(i = 0; i < 256; i++) { palette->colors[i].r = i; palette->colors[i].g = i; palette->colors[i].b = i; } } else if (png_num_palette > 0 ) { palette->ncolors = png_num_palette; for( i=0; i<png_num_palette; ++i ) { palette->colors[i].b = png_palette[i].blue; palette->colors[i].g = png_palette[i].green; palette->colors[i].r = png_palette[i].red; } } } done: /* Clean up and return */ if ( png_ptr ) { lib.png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : (png_infopp)0, (png_infopp)0); } if ( row_pointers ) { free(row_pointers); } if ( error ) { SDL_RWseek(src, start, RW_SEEK_SET); if ( surface ) { SDL_FreeSurface(surface); surface = NULL; } IMG_SetError(error); } return(surface); }
int emulate(smn8_rom *rom) { SDL_Window *window; SDL_Surface *screen; #ifdef HAVE_AUDIO SDL_AudioSpec audio_spec; #endif smn8_vm vm; emulator_state state; #ifdef HAVE_AUDIO if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) #else if(SDL_Init(SDL_INIT_VIDEO) != 0) #endif { fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError()); return EXIT_FAILURE; } #ifdef HAVE_AUDIO SDL_zero(audio_spec); audio_spec.freq = 22050; audio_spec.format = AUDIO_U16; audio_spec.channels = 2; audio_spec.samples = 4096; audio_spec.callback = audio; if(SDL_OpenAudio(&audio_spec, NULL) != 0) { fprintf(stderr, "Failed to initialize SDL audio: %s\n", SDL_GetError()); SDL_Quit(); return EXIT_FAILURE; } #endif window = SDL_CreateWindow("SMN8", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, 0); if(window == NULL) { fprintf(stderr, "Failed to create SDL Window: %s\n", SDL_GetError()); #ifdef HAVE_AUDIO SDL_CloseAudio(); #endif SDL_Quit(); return EXIT_FAILURE; } SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "1"); screen = SDL_GetWindowSurface(window); if(screen == NULL) { fprintf(stderr, "Failed to get a valid SDL Surface: %s\n", SDL_GetError()); SDL_DestroyWindow(window); #ifdef HAVE_AUDIO SDL_CloseAudio(); #endif SDL_Quit(); return EXIT_FAILURE; } state.colors[COLOR_BG] = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); #ifdef HAVE_LIME state.colors[COLOR_FG] = SDL_MapRGB(screen->format, 0x00, 0xFF, 0x00); #else state.colors[COLOR_FG] = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF); #endif SDL_FillRect(screen, NULL, state.colors[COLOR_BG]); state.vm = &vm; state.screen = screen; state.window = window; #ifndef __EMSCRIPTEN__ state.ticks = SDL_GetTicks(); #endif if(!smn8_vm_init(&vm, rom)) { smn8_vm_clear(&vm); SDL_DestroyWindow(window); #ifdef HAVE_AUDIO SDL_CloseAudio(); #endif SDL_Quit(); } #ifdef __EMSCRIPTEN__ emscripten_set_main_loop_arg(tick, &state, 0, 1); #else for(;;) { if(!tick(&state)) break; } smn8_vm_clear(&vm); SDL_DestroyWindow(window); #ifdef HAVE_AUDIO SDL_CloseAudio(); #endif SDL_Quit(); #endif return EXIT_SUCCESS; }
int main( int argc, char* args[] ) { //The timer starting time Uint32 start = SDL_GetTicks(); //Quit flag bool quit = false; //Initialize if( init() == false ) { return 1; } //Load the files if( load_files() == false ) { return 1; } //Set the wall wall[0].x = 0; wall[0].y = 0; wall[0].w = 0;//60; wall[0].h = 0;//500; wall[1].x = 0; wall[1].y = 0; wall[1].w = 640; wall[1].h = 50; /*wall[2].x = 636; wall[2].y = 60; wall[2].w = 4; wall[2].h = 490; wall[3].x = 60; wall[3].w = 580; wall[3].h = 4;*/ int bgX = 0; int bgY = 0; bool scrollBgY = false; bool scrollBgX = false; //While the user hasn't quit while( quit == false ) { //Start the frame timer fps.start(); //While there's events to handle while( SDL_PollEvent( &event ) ) { //Handle events for the player, if not dead if(myPlayer.returnHp() > 0) myPlayer.handle_input(); //If the user has pressed ESC if(event.type == SDL_KEYUP) if(event.key.keysym.sym == SDLK_ESCAPE) quit = true; //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } // Don't alow anything to move if player is dead if(myPlayer.returnHp() > 0) { //Move the player myPlayer.move(); //Move bullets for(int i=0; i < NUM_BULLETS; i++) bullets[i].move(); //Move enemies for(int i=0; i < NUM_BAD; i++) badguy[i].move(); } //Fill the screen white //SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) ); //Show the background apply_surface(0,0, background, screen ); //Show the wall for (int i = 0; i < 2; i++) { SDL_FillRect( screen, &wall[i], SDL_MapRGB( screen->format, 0x77, 0x77, 0x77 ) ); } //Show the objects on the screen, if player is not dead if(myPlayer.returnHp() > 0) { myPlayer.show(); for(int i=0; i < NUM_BULLETS; i++) bullets[i].show(); for(int i=0; i < NUM_BAD; i++) badguy[i].show(); } // Re-spawn all the enemies if(NUM_BAD_KILLED == NUM_BAD) { //// Delay three seconds //Uint32 badDelayStart = SDL_GetTicks(); //// Loop through and respawn them //if((badDelayStart - SDL_GetTicks()) >= (1000*3)) //{ for(int i = 0; i < NUM_BAD; i++) { badguy[i].respawn(i); } //} NUM_BAD_KILLED = 0; } //Render the text sprintf(debug,"HP:%d ",myPlayer.returnHp()); int tics = (1000 / FRAMES_PER_SECOND) - fps.get_ticks(); sprintf(debug + strlen(debug),"FPS:%d ",tics); sprintf(debug + strlen(debug),"Time:%d", (SDL_GetTicks() - start)/1000); //sprintf(debug + strlen(debug)," No. killed:%d",NUM_BAD_KILLED); message = TTF_RenderText_Solid( font, debug, textColor ); //If there was an error in rendering the text if( message == NULL ) return 1; // Player dead, show game over text if(myPlayer.returnHp() <= 0) { SDL_Color redText = {255,0,0}; message = TTF_RenderText_Solid(font,"Game Over",redText); apply_surface(240, 5, message, screen ); } // Player alive, show HUD else apply_surface(5, 5, message, screen ); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } //Clean up clean_up(); return 0; }
int shc_load(void) { config_setting_t *cfg = config_lookup(&CONFIG, "shortcuts"); int i; if (!cfg) return -1; for (i = 0; i < config_setting_length(cfg); i++) { SDL_Surface *icon = NULL; config_setting_t *group = config_setting_get_elem(cfg, i); config_setting_t *celem = NULL; char *filename = NULL; char *title = NULL; char *pngfile = NULL; if (group) { const char *ctmp; celem = config_setting_get_member(group, "path"); if (celem) { ctmp = config_setting_get_string(celem); if (ctmp) { filename = (char *) calloc(1, 1024); strncpy(filename, ctmp, 1023); } } celem = config_setting_get_member(group, "title"); if (celem) { ctmp = config_setting_get_string(celem); if (ctmp) { title = (char *) calloc(1, 1024); strncpy(title, ctmp, 1023); } } } else continue; if (filename && strlen(filename)) { pngfile = (char *) calloc(1, strlen(filename) + 1); strncpy(pngfile, filename, strlen(filename)); strncpy(&pngfile[strlen(pngfile) - 3], "png", 3); icon = gfx_load_image(pngfile, 0); if (!icon) icon = gfx_load_image("images/icons/game_broken.png", 0); else if (icon->w < 128 || icon->h < 74) { SDL_Surface *tmp_icon = gfx_new_surface(128, 74, 0); SDL_FillRect(tmp_icon, NULL, SDL_MapRGB((SDL_GetVideoSurface())->format, 255, 255, 255)); gfx_draw_image(icon, (128 - icon->w) / 2, (74 - icon->h) / 2, tmp_icon); SDL_FreeSurface(icon); icon = SDL_DisplayFormatAlpha(tmp_icon); SDL_FreeSurface(tmp_icon); } free(pngfile); add_shc(filename, title, icon); if (title) free(title); if (filename) free(filename); } } return 0; }
//Metodo que sirve para resaltar un elemento en el menu y actualizar los elementos //que se van mostrando void TMenu::MostrarMenu(int numMenu) { Clear(); //Hay que mover fondo circulos a otro lugar this->miImagen->fondoCirculos(); int contador2 = 0; int lineas_pantalla = (this->maxHeight -this->top) / (tamFuente + saltoLinea); bool pantallaMovida = false; if (menusD->posCampo >= menusD->posMenuScreenFin) { menusD->posMenuScreenIni++; menusD->posMenuScreenFin++; pantallaMovida = true; } else if (menusD->posCampo < menusD->posMenuScreenIni) { menusD->posMenuScreenIni--; menusD->posMenuScreenFin--; pantallaMovida = true; } int inicio=menusD->posMenuScreenIni, fin=menusD->posMenuScreenFin; if (menusD->menus[numMenu].numCampos < lineas_pantalla) fin = menusD->menus[numMenu].numCampos; //this->sangrado(numMenu); if (menusD->posMenuScreenIni > 0) { this->miImagen->pintarTriangulo (5,1,10,9,true,clBlanco); } if (menusD->posMenuScreenIni < menusD->menus[numMenu].numCampos - lineas_pantalla ) { this->miImagen->pintarTriangulo (5,screen->h - 1,10,9,false,clBlanco); } int posX=0; //Lo mismo que se hace aqui para pintar los menus, debe hacerse //en TMenuPrincipal::MostrarMenuPrincipal() for (int i = inicio; i < fin;i++) { if (i == menusD->posCampo) { TTF_SizeText(font,menusD->menus[numMenu].campo[i].nombre,&posX,NULL); this->miImagen->pintarCirculo(margenI + left + 3,margenS + top + contador2*separacion + separacion/2, separacion/2,clRojo); this->miImagen->pintarCirculo(margenI + left + 3 + posX, margenS + top + contador2*separacion+separacion/2, separacion/2,clRojo); this->setColor(clNegro); SDL_Rect pantalla = { margenI + left + 3,margenS + top + contador2*separacion +1, posX, separacion-2}; //Pintamos el texto sobresaltado en color rojo ClRojo SDL_FillRect(screen, &pantalla, SDL_MapRGB(screen->format,255,0,0)); IconosMenu(numMenu,i,margenS + top + contador2*separacion +1); } else { this->setColor(clBlanco); IconosMenu(numMenu,i,margenS + top + contador2*separacion +1); } drawText(menusD->menus[numMenu].campo[i].nombre,left, margenS + top + contador2*separacion); contador2++; } if (numMenu <= this->menusD->mensajes_menus.menus-1) { this->setColor(clBlanco); if (numMenu == 6) { objTraza->print("Antes de asignar los menus recientes",fichLang->getClave("mBorra")); //this->miImagen->pintarTitulo("Borrar ficheros recientes de la ruta:"); this->miImagen->pintarTitulo(fichLang->getClave("mBorra")); //drawText("Borrar de la ruta:",0,0); drawText(this->menusD->mensajes_menus.mensajes[numMenu].textoMensaje,0,25); } else { this->miImagen->pintarTitulo(this->menusD->mensajes_menus.mensajes[numMenu].textoMensaje); } /* else { drawText(this->mensajes_menus.mensajes[numMenu].textoMensaje,0,0); } */ } if (numMenu == 0) { //Se hace lo mismo en TMenuPrincipal::MostrarMenuPrincipal this->miImagen->pintarTitulo(this->nombreFicheroAbierto); this->verTiempoLectura(); } /* else if (numMenu == 2) { this->pintarTitulo("Opciones"); } else if (numMenu == 3) { this->pintarTitulo("Tipos de fuente"); } else if (numMenu == 4) { this->pintarTitulo("Ir a la página"); } */ SDL_UpdateRect(screen, 0, 0, 0, 0); visible = true; }
int main() { if (!init()) { return 1; } ballImg = loadImage ("ball.png"); Ball ball = Ball (screen, ballImg, SCREEN_WIDTH/2 - 8, SCREEN_HEIGHT/2 - 8, 1, 1); Paddle p1 = Paddle (screen, SCREEN_WIDTH-20, SCREEN_HEIGHT/2-PADDLE_HEIGHT/2, PADDLE_WIDTH, PADDLE_HEIGHT); Paddle p2 = Paddle (screen, 20, SCREEN_HEIGHT/2-PADDLE_HEIGHT/2, PADDLE_WIDTH, PADDLE_HEIGHT); // p1 can use default keys, p2 needs new ones bound. p2.setKeys (SDLK_w, SDLK_s); bool quit = false; bool winner = false; SDL_Event event; Timer fps; int bounceCount = 0; while (!quit) { fps.start(); if (SDL_PollEvent (&event)) { p1.handleEvents (event); p2.handleEvents (event); if (event.type == SDL_QUIT) { quit = true; } } // white out the background SDL_FillRect (screen, &screen->clip_rect, SDL_MapRGB (screen->format, 0xFF, 0xFF, 0xFF)); // update the paddles p1.draw (); p2.draw (); // update the ball ball.update(); if (!winner) { // check to see if the ball is past the paddle if (ball.getXPos() < 20) { // left player win std::cout << "right player win!" << std::endl; winner = true; } else if (ball.getXPos() > SCREEN_WIDTH - 20 - PADDLE_WIDTH) { // right player win std::cout << "left player win!" << std::endl; winner = true; } } // check to see if the ball should bounce off the right paddle if (ball.getXPos() + 6 == SCREEN_WIDTH - 20 - PADDLE_WIDTH && ball.getYPos() < p1.getYPos() + PADDLE_HEIGHT && ball.getYPos() > p1.getYPos()) { std::cout << "right bounce!" << std::endl; ball.bounce(); } SDL_UpdateWindowSurface (window); if (fps.get_ticks() < 1000 / FRAMES_PER_SECOND) { SDL_Delay ((1000 / FRAMES_PER_SECOND) - fps.get_ticks()); } } clean(); return 0; }
void calligraphy_drag(magic_api * api, int which, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect) { Point2D * curve; int i, n_points, thick, new_thick; Uint32 colr; SDL_Rect src, dest; // if (SDL_GetTicks() < calligraphy_last_time + 5) // return; calligraphy_control_points[0].x = calligraphy_control_points[1].x; calligraphy_control_points[0].y = calligraphy_control_points[1].y; calligraphy_control_points[1].x = calligraphy_control_points[2].x; calligraphy_control_points[1].y = calligraphy_control_points[2].y; calligraphy_control_points[2].x = calligraphy_control_points[3].x; calligraphy_control_points[2].y = calligraphy_control_points[3].y; calligraphy_control_points[3].x = x; calligraphy_control_points[3].y = y; calligraphy_last_time = SDL_GetTicks(); /* if ((calligraphy_control_points[0].x == calligraphy_control_points[1].x && calligraphy_control_points[0].y == calligraphy_control_points[1].y) || (calligraphy_control_points[1].x == calligraphy_control_points[2].x && calligraphy_control_points[1].y == calligraphy_control_points[2].y) || (calligraphy_control_points[2].x == calligraphy_control_points[3].x && calligraphy_control_points[2].y == calligraphy_control_points[3].y)) return; // No-op; not enough control points yet! */ n_points = calligraphy_dist(calligraphy_control_points[0].x, calligraphy_control_points[0].y, calligraphy_control_points[1].x, calligraphy_control_points[1].y) + calligraphy_dist(calligraphy_control_points[1].x, calligraphy_control_points[1].y, calligraphy_control_points[2].x, calligraphy_control_points[2].y) + calligraphy_dist(calligraphy_control_points[2].x, calligraphy_control_points[2].y, calligraphy_control_points[3].x, calligraphy_control_points[3].y); if (n_points == 0) return; // No-op; not any points to plot curve = (Point2D *) malloc(sizeof(Point2D) * n_points); calligraphy_ComputeBezier(calligraphy_control_points, n_points, curve); colr = SDL_MapRGB(canvas->format, calligraphy_r, calligraphy_g, calligraphy_b); new_thick = 40 - min((n_points /* / 2 */), 32); for (i = 0; i < n_points - 1; i++) { thick = ((new_thick * i) + (calligraphy_old_thick * (n_points - i))) / n_points; /* The new way, using an antialiased brush bitmap */ x = curve[i].x; y = curve[i].y; src.x = calligraphy_brush->w - thick / 2 - thick / 4; src.w = thick / 2 + thick / 4; src.y = 0; src.h = thick / 4; dest.x = x - thick / 4; dest.y = y - thick / 4; SDL_BlitSurface(calligraphy_colored_brush, &src, canvas, &dest); src.x = 0; src.w = thick / 2 + thick / 4; src.y = calligraphy_brush->h - thick / 4; src.h = thick / 4; dest.x = x - thick / 2; dest.y = y; SDL_BlitSurface(calligraphy_colored_brush, &src, canvas, &dest); /* Old way; using putpixel: SDL_LockSurface(canvas); for (j = -(thick / 2); j < (thick / 2) + 1; j++) { x = curve[i].x + j; y = curve[i].y - (j / 2); // 30 degrees api->putpixel(canvas, x, y, colr); api->putpixel(canvas, x + 1, y, colr); api->putpixel(canvas, x, y + 1, colr); api->putpixel(canvas, x + 1, y + 1, colr); } SDL_UnlockSurface(canvas); */ } calligraphy_old_thick = (calligraphy_old_thick + new_thick) / 2; free(curve); if (ox > x) { int tmp = ox; ox = x; x = tmp; } if (oy > y) { int tmp = oy; oy = y; y = tmp; } update_rect->x = ox - 16; update_rect->y = oy - 16; update_rect->w = (x + 16) - update_rect->x; update_rect->h = (y + 16) - update_rect->h; /* FIXME */ update_rect->x = 0; update_rect->y = 0; update_rect->w = canvas->w; update_rect->h = canvas->h; api->playsound(calligraphy_snd, (x * 255) / canvas->w, 255); }
int main(int argc, char* argv[]) { SDL_Surface *screen; SDL_Event event; SDL_Rect nativeInfo; int keypress = 0; if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; const SDL_VideoInfo* info = SDL_GetVideoInfo(); nativeInfo.w = info->current_w; nativeInfo.h = info->current_h; if (!(screen = SDL_SetVideoMode(info->current_w, info->current_h, 0, SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_RESIZABLE))) { SDL_Quit(); return 1; } SDL_WM_SetCaption("",NULL); srand(time(NULL)); ImageHandler *ih = new ImageHandler("chars16x16.bmp",16,16); SDL_Rect bounds; SDL_Rect ps = bounds; ps.x = 0*ih->bWidth; ps.y = 1*ih->bHeight; Map tilemap = Map(); std::string speed = "speednsdlkfjfklsjkldfjsdkl"; std::stringstream out; int ind = 0; clock_t before = clock(); clock_t result = clock() - before; while(!keypress) { Uint32 col1 = SDL_MapRGB(screen->format,20,20,20); Uint32 col2 = SDL_MapRGB(screen->format,0,255,0); SDL_FillRect(screen,NULL,col1); bounds.x=0; bounds.y=0; ind++; result = clock() - before; out.str(""); out.clear(); out << result << " "; before = clock(); ih->putStr(out.str().c_str(),col1,col2,&bounds,screen); bounds.y=1*ih->bHeight; time_t rawtime; time(&rawtime); ih->putStr(ctime(&rawtime),col1,col2,&bounds,screen); int xpos,ypos; SDL_GetMouseState(&xpos,&ypos); bounds.x=floor(xpos/ih->bWidth)*ih->bWidth; bounds.y=floor(ypos/ih->bHeight)*ih->bHeight; SDL_Rect t_bounds = bounds; for(int i = 0; i<tilemap.w*tilemap.h; i++) { Tile tilecurrent = tilemap.tiles[i]; t_bounds.x=bounds.x+(ih->bWidth*(i%tilemap.w)); t_bounds.y=bounds.y+(ih->bHeight*(i/tilemap.w)); if(t_bounds.x+ih->bWidth <= screen->w && t_bounds.y+ih->bHeight <= screen->h) { ih->putChar(tilecurrent.character,col1,col2,&t_bounds,screen); } } while(SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: keypress = 1; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_q: keypress = 1; break; case SDLK_w: if(ih->bWidth == 16) { delete ih; ih = new ImageHandler("chars24x24.bmp",24,24); } else { delete ih; ih = new ImageHandler("chars16x16.bmp",16,16); }; SDL_SetVideoMode(info->current_w,info->current_h, 0, screen->flags); break; case SDLK_F11: SDL_LockSurface(screen); if(((screen->flags)&SDL_FULLSCREEN) == SDL_FULLSCREEN) { SDL_UnlockSurface(screen); SDL_SetVideoMode(nativeInfo.w/2, nativeInfo.h/2, 0, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_RESIZABLE); } else { SDL_UnlockSurface(screen); SDL_SetVideoMode(nativeInfo.w, nativeInfo.h, 0, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_FULLSCREEN); }; break; default: break; } break; case SDL_VIDEORESIZE: SDL_LockSurface(screen); SDL_SetVideoMode(event.resize.w,event.resize.h, 0, screen->flags); SDL_UnlockSurface(screen); break; default: break; } } SDL_Flip(screen); } SDL_Quit(); return 0; }