Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

SDL problem

Name: Anonymous 2009-11-30 3:58

Ok, this is my minimal testcase for a problem I'm having with SDL_CreateRGBSurface(), or something around that area...  It's supposed to display a white box but something is wrong with the mask values I give to SDL_CreateRGBSurface and the only color I can get is this dark red.  I know it has nothing to do with the palette values so don't even bother.  Can anyone who's familiar with SDL tell me how to fix this shit?

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <SDL/SDL.h>

void setpalette(SDL_Surface* surface);

/*** Main Entry ***/
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) {

        SDL_Surface* screen;
        SDL_Event event;


        /* Start SDL */
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
                printf("Failed to initialize a subsystem.\n");
                exit(1);
        }


        assert((screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE)) != NULL);


        setpalette(screen);


        // Clear the screen
        SDL_FillRect(screen, NULL, 0);

        SDL_Surface *area;
        SDL_Rect rectarea = { 100, 100, 400, 400 };

        /*** FAIL TIEM ***/
        area = SDL_CreateRGBSurface(SDL_SWSURFACE, 111, 221, 8, 0x000000FF,0x0000FF00,0x00FF0000,0);

        assert(area != NULL);
        assert(!SDL_FillRect(area, NULL, 15));   // Color 15 should give me a white box
        SDL_BlitSurface(area, NULL, screen, &rectarea);

        SDL_Flip(screen);
        SDL_FreeSurface(area);


        while (1) {
                SDL_PollEvent(&event);

                if (event.key.type == SDL_KEYDOWN) {
                        // Escape: exit the program
                        if (event.key.keysym.sym == SDLK_ESCAPE)
                                break;
                }
        }

        SDL_Quit();
        return 0;
}


void setpalette(SDL_Surface* surface) {
        SDL_Color colors[256];
        colors[0].r = 0; colors[0].g = 0; colors[0].b = 0;
        colors[15].r = 255; colors[15].g = 255; colors[15].b = 255;
        SDL_SetColors(surface, colors, 0, 256);
}

Name: Anonymous 2009-11-30 4:10

>>1
stackoverflow.com

You will find no programmers here.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !frozEn/KIg 2009-11-30 6:55

http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurface
>Allocate an empty surface (must be called after SDL_SetVideoMode)



__________________________________
http://bayimg.com/image/aadbjaace.jpg
My Blog: http://frozenvoid.blogspot.com/
«Our eyes are made to see forms in light; light and shade reveal these forms; cubes, cones, spheres, cylinders or pyramids are the great primary forms which light reveals to advantage; the image of these is distinct and tangible within us without ambiguity. It is for this reason that these are beautiful forms, the most beautiful forms. Everybody is agreed to that, the child, the savage and the metaphysician. »

Name: Anonymous 2009-11-30 10:09

you need to setpalette(area) before you fill it. currently it's interpreting the 15 as an RGB value, hence the dark red.

Name: Anonymous 2009-11-30 18:44

>>4
Thank you, sir =)

Name: Anonymous 2009-11-30 19:39

Don't use #include <SDL/SDL.h>. The directory it's installed into might vary from one system to the next; just use <SDL.h> and use `sdl-config --cflags` in your Makefile to get the proper -I option for it.

Name: Anonymous 2009-11-30 19:44

Oh and you probably shouldn't be using WinMain with SDL. Take a look at SDL_main.h; it provides a (weirdass) wrapper and some extra stuff in order to get your program to build and run on multiple platforms. I really recommend it; there's not really any point in using SDL over DirectX or whatever if you're not trying to be cross-platform.

Name: Anonymous 2009-11-30 20:24

>>6,7
Alright, thanks for the info.  I just put my SDL headers in /include/SDL/ because I figured it would be better than dumping them with everything else for some reason.... didn't even think that this wouldn't be portable at all.

Name: Anonymous 2009-12-04 19:00

>>6
where in the Makefile do I need to put this?  it doesn't seem to work anywhere for me.

Name: Anonymous 2009-12-04 21:30

>>9
I just typed this up right now, so you might need to tweak it a bit. It "should" work, and I use this general layout in my own projects. For BSD make, I dunno lol.

CC := gcc
CFLAGS := -g -Wall -std=gnu99 $(shell sdl-config --cflags)
LDFLAGS := $(shell sdl-config --libs)

APPNAME := hairyballs
SRCFILES := sweat.c pubes.c leftnut.c rightnut.c semen.c
HEADERS := testicles.h

OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))

.PHONY: all clean
all: $(PROGRAM)
clean:
    $(RM) *.o $(PROGRAM)
$(PROGRAM): $(OBJFILES)
    $(CC) $(LDFLAGS) -o $@ $^

# you could also put gcc -MM etc. output here if you want.
$(OBJFILES): Makefile $(HEADERS)

Name: Anonymous 2009-12-04 21:32

fuck you shiichan

Name: Anonymous 2009-12-04 21:33

and shit, I apparently couldn't decide to call it APPNAME or PROGRAM. Pick one.

Don't change these.
Name: Email:
Entire Thread Thread List