Andrea Catalini
Andrea Catalini

Reputation: 172

Trouble with drawing a pixel through Draw_Pixel() of SDL_Draw library

It might sound a little strange, but I can't correctly use the Draw_Pixel() and Draw_Line() functions of SDL_Draw.h I've googled and people state: It's very simple to use, but unfortunately... not for me. I've written a very simple piece of code but it doesn't show me the pixel, I tried also with a line, but nothing as well.

The simple code is:

#include <SDL.h>
#include "SDL_draw.h"     
   int main(int argc, char** argv)
    {
        SDL_Surface* surf;
        if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
            return -1;
        }

        if((surf = SDL_SetVideoMode(WIDTH, HEIGTH, BBP, FLAGS)) == NULL) {
            return -1;
        }
    Uint32 myColor = SDL_MapRGB( surf->format, 255, 25, 23); //this is the red color
        Draw_Pixel(surf, 45, 45, myColor);
        Draw_Line(surf, 45, 20, 90, 100, myColor);

        SDL_Quit();

        return 1;
    }

The x,y coordinates are just random. I'm trying to see the result with breakpoints in Visual Studio.

Can anyone tell me where I'm mistaking?

Upvotes: 0

Views: 329

Answers (1)

this
this

Reputation: 5290

You have to update your surface by calling SDL_Flip( SDL_Surface * screen) ;

And add a delay before exiting the program, otherwise you wont see the window.

Upvotes: 1

Related Questions