🔒 Locked
Problem with SDL...
Advertisement
Original Post
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.
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:
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
|
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
Here is a link to my example code
Click Me!
-----------------------------
kevin@mayday-anime.com
http://games.mayday-anime.com
Edited by - grasshopa55 on November 21, 2001 9:25:38 AM
Click Me!
-----------------------------
kevin@mayday-anime.com
http://games.mayday-anime.com
Edited by - grasshopa55 on November 21, 2001 9:25:38 AM
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.
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.
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.)
"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
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
Any code you write for SDL in Linux should compile and function properly in Windows.
[Resist Windows XP''s Invasive Production Activation Technology!]
[Resist Windows XP''s Invasive Production Activation Technology!]
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
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.
"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
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
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.
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.
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.
Can't find "Multithreaded DLL" anywhere in MSVC++. Does anyone who has/uses MSVC++ know how to make Simple DirectMedia Layer work with it!?!?
Here is the the debug message:
--------------------Configuration: SDL Basic - Win32 Debug--------------------
Linking...
msvcrt.lib(MSVCRT.dll) : error LNK2005: _exit already defined in LIBCD.lib(crt0dat.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strncpy already defined in LIBCD.lib(strncpy.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _fclose already defined in LIBCD.lib(fclose.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __isctype already defined in LIBCD.lib(isctype.obj)
LIBCD.lib(crt0init.obj) : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/SDL Basic.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
SDL Basic.exe - 5 error(s), 1 warning(s)
Theres the code.
By the way, I didn't read the tutorial yet. I justr copied the code without a clue of what it does to see if I could get it to work. I am assuming that it creates a window but all I get is a pile of linking errors.
Edited by - Drizzt DoUrden on November 23, 2001 12:39:37 AM
Here is the the debug message:
--------------------Configuration: SDL Basic - Win32 Debug--------------------
Linking...
msvcrt.lib(MSVCRT.dll) : error LNK2005: _exit already defined in LIBCD.lib(crt0dat.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strncpy already defined in LIBCD.lib(strncpy.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _fclose already defined in LIBCD.lib(fclose.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __isctype already defined in LIBCD.lib(isctype.obj)
LIBCD.lib(crt0init.obj) : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/SDL Basic.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
SDL Basic.exe - 5 error(s), 1 warning(s)
#include <stdio.h> |
Theres the code.
By the way, I didn't read the tutorial yet. I justr copied the code without a clue of what it does to see if I could get it to work. I am assuming that it creates a window but all I get is a pile of linking errors.
Edited by - Drizzt DoUrden on November 23, 2001 12:39:37 AM
This is how I do it:
Create a new Win32 project
Goto Project->Settings->C/C++->Code Generation and set the "run-time library" to Multithreaded (I don''t know if that is required or not, actually)
Goto Project->Settings->Link->General and replace the "Object/library modules" textbox with: msvcrt.lib libc.lib libcp.lib kernel32.lib sdl.lib sdlmain.lib
Check "Ignore all default libraries"
Make sure to use "int main(int argc, char *argv[])" as your entry point not "int main(void)" or WinMain(...)
[Resist Windows XP''s Invasive Production Activation Technology!]
[Resist Windows XP''s Invasive Production Activation Technology!]
Thank you Null and Void. I did all of those things, and a few errors were resolved which I made me scream halleulah(also makes me wish I could spell it.) but I still get this:
--------------------Configuration: SDL Basic - Win32 Debug--------------------
Compiling...
FirstSDL.cpp
Linking...
msvcrt.lib(bsku.obj) : error LNK2001: unresolved external symbol __imp__MessageBoxA@16
Debug/SDL Basic.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
SDL Basic.exe - 2 error(s), 0 warning(s)
--------------------Configuration: SDL Basic - Win32 Debug--------------------
Compiling...
FirstSDL.cpp
Linking...
msvcrt.lib(bsku.obj) : error LNK2001: unresolved external symbol __imp__MessageBoxA@16
Debug/SDL Basic.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
SDL Basic.exe - 2 error(s), 0 warning(s)
I just followed my own steps using the code you posted, and it compiled fine. You aren''t calling MessageBox, are you? Remember that SDL is crossplatform, but MessageBox isn''t
. You can use printf in SDL and it will go to a file called "stdout.txt" in the same directory as the program (in Windows, in Linux it goes to the console or no where
).
Also, don''t even bother including windows.h unless you have to due to Microsoft''s OpenGL headers. But, if you do, do it within a ifdef/endif block for _WIN32.
[Resist Windows XP''s Invasive Production Activation Technology!]
Also, don''t even bother including windows.h unless you have to due to Microsoft''s OpenGL headers. But, if you do, do it within a ifdef/endif block for _WIN32.
[Resist Windows XP''s Invasive Production Activation Technology!]
I copied the code directly from cone3d.gamedev.net''s first tutorial. Their code is for Linux, and everyone keeps saying that there is no difference between Linux and Windows SDL, but I think they are leaving out the fact that C++ is there, too. I don''t know what changes from Linux to Windows from SDL or C++ or the operating system itself.
I don''t see a call to MessageBox anywhere, but it is 1:20 AM here and my eyes are half shut so I might have missed it.
BTW: I got rid of Windows.h alittle while ago. I noticed that there was no call to anything windows related.
I don''t see a call to MessageBox anywhere, but it is 1:20 AM here and my eyes are half shut so I might have missed it.
BTW: I got rid of Windows.h alittle while ago. I noticed that there was no call to anything windows related.
I''m not sure what is wrong then, it worked fine for me by following my own instructions and pasting that source into a .cpp file. My engine compiles (and runs
) without any changes in Windows and Linux, so SDL really is 100% portable
.
[Resist Windows XP''s Invasive Production Activation Technology!]
[Resist Windows XP''s Invasive Production Activation Technology!]
quote:
Original post by Drizzt DoUrden
I don''t see a call to MessageBox anywhere, but it is 1:20 AM here and my eyes are half shut so I might have missed it.
Yeah, that''s why the thoughtful dudes at MS put a find tool in the IDE, just for days like this when you''ve been up all night looking for an extraneous comma in a 1.5k line source file...
No, there is no call to messagebox.
But I am a genius.
The problem was the libraries you told me to link, Null and Void. While they belonged there, too, so did a few other default ones that you told me to replace. I re-added them and it works like a charm!
I needed all of these .libs:
msvcrt.lib libc.lib libcp.lib sdl.lib sdlmain.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib
Everything else was O.K. and there was no call to MessageBox anywhere.
Thank you guys for your help!
But I am a genius.
The problem was the libraries you told me to link, Null and Void. While they belonged there, too, so did a few other default ones that you told me to replace. I re-added them and it works like a charm!
I needed all of these .libs:
msvcrt.lib libc.lib libcp.lib sdl.lib sdlmain.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib
Everything else was O.K. and there was no call to MessageBox anywhere.
Thank you guys for your help!
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement