Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL/SDL.h>
- //void putpixel(SDL_Surface* screen, int x, int y)
- //{
- // Uint8* pixels = (Uint8*)screen->pixels;
- // Uint8* pixel = pixels + y*screen->pitch + x; // offset of pointer
- // *pixel = SDL_MapRGB(screen->format,0xff,0xff,0xff);
- //}
- // 32 Bit (not yet working correctly)
- void putpixel(SDL_Surface* screen, int x, int y)
- {
- Uint32* pixels = (Uint32*)screen->pixels;
- Uint32* pixel = pixels + y*screen->pitch/4 + x; // offset of pointer
- *pixel = SDL_MapRGB(screen->format,0xff,0xff,0xff);
- }
- int main(int argc, char** argv)
- {
- SDL_Init(SDL_INIT_EVERYTHING);
- SDL_Surface *screen;
- // screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
- screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
- bool running = true;
- const int FPS = 30;
- Uint32 start;
- for(int i = 0; i < 100; i += 1) {
- putpixel(screen,i,10);
- }
- putpixel(screen,20,40);
- while(running) {
- start = SDL_GetTicks();
- SDL_Event event;
- while(SDL_PollEvent(&event)) {
- switch(event.type) {
- case SDL_QUIT:
- running = false;
- break;
- }
- }
- //logic
- //render
- SDL_Flip(screen);
- if(1000/FPS > SDL_GetTicks()-start) {
- SDL_Delay(1000/FPS-(SDL_GetTicks()-start));
- }
- }
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement