Float And Sdl Problems


charlieb

Member
Joined
Nov 30, 2006
Messages
116
Hi,
I'm trying to compile the and simple SDL demo with open2x. I had some problems to start with but now it works when I compile it like this:

open2x-gcc -c -Wall -I/usr/local/open2x/include -I/usr/local/open2x/include/SDL -D_REENTRANT demo.c -o demo.o
open2x-gcc demo.o -o helloworld.gpe -msoft-float-L/usr/local/open2x/lib -Wl,-rpath,/usr/local/open2x/lib -lSDL -lpthread -lm -ldl

I actually use `/usr/local/open2x/bin/sdl-config --cflags` and `/usr/local/open2x/bin/sdl-config --static-libs` for compiling but I thought the expanded version would be more instructive.

If I add a float to the source then at runtime I get the following:
./helloworld.gpe: relocation error: ./helloworld.gpe: undefined symbol: __extendsfdf2

If I compile it with the static flag I don't get the have any problem with floats but instead of the image the program is supposed to display I get some unpleasant black and white bands on the screen. The app responds to events as expected and when I quit the app I see a flash of the image it should be displaying just before it exits to the menu.
Any ideas how to solve or investigate this?

Cheers,
Charlie
 
hi charlie,
been scratching around and got this far with it...
i'm initialising with
screen = SDL_SetVideoMode(GP2X_WIDTH,
GP2X_HEIGHT,
16,
SDL_DOUBLEBUF | SDL_HWSURFACE
);

SDL_PixelFormat *pf = NULL;
pf = screen->format;
black = SDL_MapRGB(pf, 0x00, 0x00, 0x00);

and then v. last thing in the game loop is
SDL_Flip(screen);
SDL_FillRect(screen, NULL, black);

although sdl docs suggest that its flip for hw and fill for soft, but both seem to be needed.
i'm also still getting a mangled screen if i use any kind of optimisation (-O3 etc),
only -O0 is good.
this is using static linkage, open2x and hw sdl.

hope it helps some.

edited for explaining where 'black' came from
 
Poddy,
I actually managed to get half way to solving this. It seems to all depend on the order of the arguments. The compile command that worked for me was
open2x-gcc main.o matrix.o figures.o fixed.o -o bin/wire3d.gpe -lSDL_gfx -msoft-float -lm -lg -lpthread -static `/usr/local/open2x/bin/sdl-config --static-libs`
note that the object files (.o) are before all the library references. Normally I like to put the .o at the end. I recall the position of the -static matters as well but in any case that works for SDL *but* I still can't use floats, despite the -msoft-float. I hadn't tried any optimization settings so that's interesing (-O2 is the defaule IIRC).

SDL_Flip just swaps the buffers, it doesn't clear them. If you aren't going to re-draw the entire frame you do indeed need to do an SDL_FillRect(surface, NULL, colour).

Are you using any floats in your program?

Cheers,
Charlie

P.S. Have a look at this thread, it covers most of the same ground.
 
Last edited by a moderator:
hi charlie,
seems we're all getting subtly different results?

lobbed a float in, didn't do anything with it, just initialised it, but should still count i guess?

compiled and ran fine.

i'm using this as a makefile if its any use
Code:
# Global definitions

CCPREFIX  = open2x-
CC		= ${CCPREFIX}gcc
STRIP	 = ${CCPREFIX}strip
AS		= ${CCPREFIX}as

PREFIX	= /usr/local/open2x
OBJS	  = mat.o
BIN	   = mat.gpe 

# Platform specific definitions 

VPATH	  += ..
CFLAGS	 += -O0 -DGP2X_BUILD
CFLAGS	 += -funroll-loops -fstrength-reduce -fstrict-aliasing -fexpensive-optimizations -falign-functions -fweb -frename-registers -fomit-frame-pointer -ffast-math -fno-builtin -fno-common -finline -finline-functions
CXXFLAGS   = ${CFLAGS} -fno-exceptions -fno-rtti
ASFLAGS	   = ${CFLAGS}
INCLUDES   = -I${PREFIX}/include -I${PREFIX}/include/SDL
LIBS	   = -L${PREFIX}/lib -lSDL -lpthread -lz -lm -static

# Compilation:

.SUFFIXES: .cpp

%.o: %.cpp
	${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<

all:	${OBJS}
	${CC} ${OBJS} ${LIBS} -o ${BIN}  
	${STRIP} ${BIN}

clean:
	rm -f *.o ${BIN} 

linux:
	make clean
	make -f ./makefile.linux

edited because i read the other thread :)

codeblocks looks interesting, might give that a go.
weird about the sdl flip, though.
from tfm...
On hardware that doesn't support double-buffering, this is equivalent to calling SDL_UpdateRect (screen, 0, 0, 0, 0)
way i read it was that this implies you can just do a flip with SDL_DOUBLEBUF | SDL_HWSURFACE

live & learn :)
 
On hardware that doesn't support double-buffering, this is equivalent to calling SDL_UpdateRect (screen, 0, 0, 0, 0)
way i read it was that this implies you can just do a flip with SDL_DOUBLEBUF | SDL_HWSURFACE
Your makefile worked! I'm happy. I also moved the -staic flag in my makefile to where it is in yours and it still worked. I didn't need to turn off optimization. This whole arguement order thing is messing with my mind but at least it works now. Here's my makefile for reference:
Code:
GP2XDEV=/usr/local/open2x
PATH+=:$(GP2XDEV)/bin

CFLAGS=-c -Wall
LDFLAGS=-lm -lg -lpthread -lSDL
GPLDFLAGS=`$(GP2XDEV)/bin/sdl-config --static-libs` -static
SOURCES=boids.c sdl-main.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLEPC=boids
EXECUTABLEGP=boids.gpe
DEST=bin

ifdef arm
CC=open2x-gcc
CFLAGS+=-msoft-float -D_GP2X_ -I$(GP2XDEV)/include `$(GP2XDEV)/bin/sdl-config --cflags`
else
CC=gcc
CFLAGS+=-D_PC_ -I/usr/include/SDL
endif

all:
	make cleanobjs
	make pc
	make cleanobjs
	make arm=1 gp
	make cleanobjs

pc: $(SOURCES) $(EXECUTABLEPC)

gp: $(SOURCES) $(EXECUTABLEGP)

$(EXECUTABLEPC): $(OBJECTS) 
	$(CC) $(LDFLAGS) $(OBJECTS) -o $(DEST)/$@

$(EXECUTABLEGP): $(OBJECTS) 
	$(CC) $(OBJECTS) -o $(DEST)/$@ $(GPLDFLAGS) $(LDFLAGS) 

.c.o:
	$(CC) $(CFLAGS) $< -o $@

cleanobjs:
	rm -f $(OBJECTS)

clean:
	-rm -f $(DEST)boids $(DEST)/boids.gpe *~ *.o


fixed:
	gcc -Wall -o $(DEST)/fixed fixed.c

On hardware that doesn't support double-buffering, this is equivalent to calling SDL_UpdateRect (screen, 0, 0, 0, 0)
way i read it was that this implies you can just do a flip with SDL_DOUBLEBUF | SDL_HWSURFACE
You can just do SDL_Flip with either if all you want to do is update the whole screen. AFAIK neither of these commands changes the conent of the surface they just updates the screen; in either case if you want to clear the screen before you redraw the frame you need to do a drawing operation like SDL_FillRect.

Cheers,
Charlie
 
Last edited by a moderator:
Back
Top