Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

HolyFish

Problem with SDL...

This topic is 6227 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After I read your tutorials about SDL I started to write my own SDL program. But I have a problem : when I compile my program (in a DOS screen) the screen is just black. Oh yeah, if i don''t use ''getch()'' the screen always goes away. What am I doing wrong ? here is my code (don''t mind my variable and function names, they are all in Dutch :-) ) //////////////////////////CODE///////////////////////////////// #include #include #include #include "SDL/SDL.h" SDL_Surface *Beeld; SDL_Surface *Bal; void InitBal() { Bal = SDL_LoadBMP("balletje.bmp"); } void TekenBal(SDL_Surface *img, int x, int y) { SDL_Rect dest; dest.x = x; dest.y = y; SDL_BlitSurface(img, NULL, Beeld, &dest); } int main(int argc, char *argv[]) { if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { printf("Unable to init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); Beeld = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF); InitBal(); TekenBal(Bal, 50,50); getch(); return 0; } ////////////////////////CODE/////////////////////////////////// Thanks in advance ! Bert.

Share this post


Link to post
Share on other sites
Advertisement
You have no real message loop. In order for the window to remain, you want to wait until a quit message has been sent. Here is an example:
  
// Look for our messages

while( SDL_WaitEvent( &event ) >= 0 )
{
// we got a message

// lets see what it is

switch( event.type ) {
// we place any case for any message we want to process

// the event filter function does work on our event before we

// process it here. Since this is a very simple program, all we

// handle is quit and we have no event filter

case SDL_QUIT:
{
// Close our program

exit( 0 );
}
break;
}
}


As you can see, without this, the program just runs and exits.

-----------------------------
kevin@mayday-anime.com
http://games.mayday-anime.com

Edited by - grasshopa55 on November 21, 2001 9:20:13 AM

Share this post


Link to post
Share on other sites
grasshopa55 is right. You need to have some loop-like thingy.
One REALLY easy way to do it is:

for(int i=0;i<10000;i++) TekenBal(Bal, 50,50);

You still would need to add some event handling stuff. Check out lesson 2 or 3 for some loops with event handling -n- stuff. Just replace DrawScene(...) with TekenBal(...) in these loops.



---
cone3d
http://cone3d.gamedev.net
Multitasking - screwing up several things at once.

Share this post


Link to post
Share on other sites
Does that .zip file you gave contain Windows code with SDL, or Linux? (Never used SDL and hoping it is Windows so I can figure it out, as I have been trying to do.)

Artificial intelligence is the devil... resist intelligent NPC''s


"He who fights with monsters should look to it that he himself does not become a monster... when you gaze long into the abyss, the abyss also gazes into you..."~Friedrich Nietzsche

Share this post


Link to post
Share on other sites
quote:
Original post by Drizzt DoUrden
Does that .zip file you gave contain Windows code with SDL, or Linux? (Never used SDL and hoping it is Windows so I can figure it out, as I have been trying to do.)

Artificial intelligence is the devil... resist intelligent NPC''s


"He who fights with monsters should look to it that he himself does not become a monster... when you gaze long into the abyss, the abyss also gazes into you..."~Friedrich Nietzsche


if you visit www.libsdl.org, you can find some basic apps to use as a starting point for your projects...



"And that''s the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer

Share this post


Link to post
Share on other sites
Does Linux use the same includes?

Does Linux have the same functions?

Does Linux use the same libraries?

Is Linux code written differently? aka the C++ code.


I don''t know what things change from Linux to Windows.

Artificial intelligence is the devil... resist intelligent NPC''s


"He who fights with monsters should look to it that he himself does not become a monster... when you gaze long into the abyss, the abyss also gazes into you..."~Friedrich Nietzsche

Share this post


Link to post
Share on other sites
When you use dev-c++ (with mingw32 (gcc for windows)) then all your code is (95% of the time) directly compilable in linux.
You only have different compile commands in linux and windows. You usually do not need to change the code. You must also have the same libraries (like SDL, ...) in windows and linux.


---
cone3d
http://cone3d.gamedev.net
Multitasking - screwing up several things at once.

Share this post


Link to post
Share on other sites
I use MSVC++6 and I keep getting tons of linking errors running your code. I downloaded the SDL libraries and headers off of www.libsdl.org for Windows, and I put them in the correct places. I also added sdl.lib to my project. I still get linking errors.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!