• HomeBoards
  • RulesRules
  • HelpHelp
  • WikiWiki
  • Donate

Author Topic: SDL Question  (Read 3151 times)

madcat1990

  • Guest
SDL Question
« on: March 02, 2010, 11:17:45 pm »
Code: [Select]
#include <stdio.h>
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"

#define DINGOO_BUTTON_UP            SDLK_UP
#define DINGOO_BUTTON_DOWN          SDLK_DOWN
#define DINGOO_BUTTON_RIGHT         SDLK_RIGHT
#define DINGOO_BUTTON_LEFT          SDLK_LEFT
#define DINGOO_BUTTON_R             SDLK_BACKSPACE
#define DINGOO_BUTTON_L             SDLK_TAB
#define DINGOO_BUTTON_A             SDLK_LCTRL
#define DINGOO_BUTTON_B             SDLK_LALT
#define DINGOO_BUTTON_X             SDLK_SPACE
#define DINGOO_BUTTON_Y             SDLK_LSHIFT
#define DINGOO_BUTTON_SELECT        SDLK_ESCAPE
#define DINGOO_BUTTON_START         SDLK_RETURN
#define DINGOO_BUTTON_END           SDLK_UNKNOWN


void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination)
{
     //Make a temporary rectangle to hold the offsets
     SDL_Rect offset;
     
     //Give the offsets to the rectangle
     offset.x = x;
     offset.y = y;
     
     //Blut the surface
     SDL_BlitSurface( source, NULL, destination, &offset );
}





int main(int argc, char** argv)
{
SDL_Surface *background = NULL;
SDL_Surface *message = NULL;
SDL_Surface *screen = NULL;
SDL_Event event;
TTF_Font *font;
font=TTF_OpenFont("font.ttf", 12);
SDL_Color textColor = { 255, 255, 255 };
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Set up screen
screen = SDL_SetVideoMode( 320, 240, 16, SDL_SWSURFACE );
//SDL_ShowCursor( SDL_DISABLE );
message = TTF_RenderText_Solid( font, "The quick brown fox jumps over the lazy dog", textColor );

apply_surface( 0, 0, message, screen );
SDL_Flip(screen);
SDL_Delay( 8000 );

SDL_FreeSurface( message );

//Close the font that was used
TTF_CloseFont( font );
//Quit SDL_ttf
TTF_Quit();
//Quit SDL
SDL_Quit();

return 0;
}

this prints out nothing D: What am I doing wrong?

darfgarf

  • Guest
Re: SDL Question
« Reply #1 on: March 03, 2010, 09:59:52 am »
check the colour you're giving the ttf_render, using SDL_colourformat(screen->format, 255, 255, 255) or whatever the function is would be a better way to map it (as the screen format might not take a byte for each pixel/whatever)

and check the return value of the ttf_render, i had quite a few problems last time i used sdl_ttf, along with it corrupting the program stack whenever it renders anything, but that's most probably not your problem XD

joyrider

  • Posts: 220
    • Willems Soft
Re: SDL Question
« Reply #2 on: March 03, 2010, 11:24:40 am »
also i'm not certain but i believe TTF_init can only be called after SDL was inited !

and use error handling, sdl_init, TTF_init etc give back results on which you can check to see if something went wrong with the function call :)

edit:
actually where is your TTF_init call ???
« Last Edit: March 03, 2010, 11:26:46 am by joyrider »

darfgarf

  • Guest
Re: SDL Question
« Reply #3 on: March 03, 2010, 02:18:15 pm »
wow can't believe i overlooked that XD that's probably a problem

madcat1990

  • Guest
Re: SDL Question
« Reply #4 on: March 03, 2010, 09:21:56 pm »
ok, i added TTF_Init(); before SDL_Init();

still black screen

edit : it works now :D had to add TTF_init before any loading (Which I completelly forgot)

thanks!

Though, I have another problem, the screen never clears itself, how do I clear it?

edit : Again, nvm, got it : SDL_FillRect(screen, NULL, 0);
« Last Edit: March 03, 2010, 09:57:39 pm by madcat1990 »

schanall

  • Posts: 139
Re: SDL Question
« Reply #5 on: March 07, 2010, 05:46:05 pm »
How do you compile your code? I have installed the dingux-toolchain into /opt. When I compile a simple program, I don't have any errors. But when I include s.th. like #include "SDL/SDL_ttf.h" I can compile with gcc, but not with mipsel-gcc.
I says
Code: [Select]
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libSDL.so when searching for -lSDL
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libSDL.a when searching for -lSDL
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libSDL.so when searching for -lSDL
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libSDL.a when searching for -lSDL
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libSDL_ttf.so when searching for -lSDL_ttf
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libSDL_ttf.a when searching for -lSDL_ttf
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libSDL_mixer.so when searching for -lSDL_mixer
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libSDL_mixer.a when searching for -lSDL_mixer
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libSDL_image.so when searching for -lSDL_image
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libSDL_image.a when searching for -lSDL_image
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
/opt/mipsel-linux-uclibc/usr/bin/../lib/gcc/mipsel-linux-uclibc/4.3.3/../../../../mipsel-linux-uclibc/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc
/tmp/ccEribkb.o: In function `load_image(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/phobos/work/SDL/lesson03/lesson03.cpp:27: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const'
/tmp/ccEribkb.o: In function `main':
/home/phobos/work/SDL/lesson03/lesson03.cpp:98: undefined reference to `std::allocator<char>::allocator()'
/home/phobos/work/SDL/lesson03/lesson03.cpp:98: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/home/phobos/work/SDL/lesson03/lesson03.cpp:98: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/phobos/work/SDL/lesson03/lesson03.cpp:98: undefined reference to `std::allocator<char>::~allocator()'
/home/phobos/work/SDL/lesson03/lesson03.cpp:98: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/phobos/work/SDL/lesson03/lesson03.cpp:98: undefined reference to `std::allocator<char>::~allocator()'
/tmp/ccEribkb.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

This my command
Code: [Select]
gcc -g -Wall `sdl-config --cflags` `sdl-config --libs` -o example1 lesson03.cpp -lSDL -lSDL_ttf -lSDL_mixer -lSDL_image


darfgarf

  • Guest
Re: SDL Question
« Reply #6 on: March 07, 2010, 06:02:01 pm »
it's trying to use the system libraries on your computer, and failing as they're not compiled for the dingoo.  it's sdl-configs fault, it's using the systems one instead of the dingoos one (i've renamed my one for the dingoo to mipsel-linux-sdl-config), and make sure the path variable is all ok for it all

schanall

  • Posts: 139
Re: SDL Question
« Reply #7 on: March 07, 2010, 06:26:18 pm »
Thank you very much for your reply :)

But I'm not sure what exactly to rename? I have found "/opt/mipsel-linux-uclibc/usr/bin/sdl-config"

My $PATH also displays an error:

Code: [Select]
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/mipsel-linux-uclibc/usr/bin: No such file or directory

I have checked it, the path is o.k. I made an
Code: [Select]
export PATH="${PATH}:/opt/mipsel-linux-uclibc/usr/bin"

EDIT: I just tried the code from madcat1990 . This works for me! I think I used a lib that does not exists for dingux-sdl
« Last Edit: March 07, 2010, 06:32:32 pm by schanall »

 

Post a new topic
Post a new topic