SDL problem...
downloaded the SDL library, and in the "showimage.c" file, it's coming up with this error... In function `void draw_background(SDL_Surface*)' invalid conversion from `void*' to `Uint8*' any ideas on how to fix this? ----------------
My name is Hermes. I became tamed by devouring my own wings.
If you are building the SDL library, which I assume you are, you will need to make a C project, not a C++. If you want to do it in C++, you will have a lot of fixing these conversion problems. I thought there would only be a few of them, but there are a lot! I had to eventually stop due to other C->C++ compiling errors.
If you do not have a C-compiler, you can use Dev-CPP IDE and make SDL in that. Just make sure to compile in C. I am not sure how to do so in Visual Studio.
- Drew
If you do not have a C-compiler, you can use Dev-CPP IDE and make SDL in that. Just make sure to compile in C. I am not sure how to do so in Visual Studio.
- Drew
If you use the included project files then you shouldn't have a problem but like Drew said - if you compile it as a C++ project then be prepared for a few thousand tpye conversion warnings.
how would i go about compiling it? do i have to make a new project and manually copy the code into new files of the same name, or is there an easier way of doing it?
i'm in dev-c++ by the way
--------------------------
i'm in dev-c++ by the way
--------------------------
My name is Hermes. I became tamed by devouring my own wings.
**Note** This is the way I just made up. There are probabally easier, faster, and better ways. (If anyone knows easier ways with Dev, please share [smile] I feel my method is a bit OBTUSE)
After you download the source. You will need to extract it.
Now create a new Dev-CPP project. It should be a "C" Dynamic Link Library. I named mine SDL. Close and do not save the 'dllmain.c' and 'dllmain.h' files that popup now.
Copy over the files in the 'src' folder into your new Dev-CPP project's folder. You will also need to copy over the contents of the 'include' folder into the project folder as well. Hit not to any replace dialogs.
Now right click on the workspace and choose add to project. Select all of the .h and .c files in the base directory. Now if you try and compile, it will compain about header files not being found. First, 'SDL_Leaks.h'.
To get around this we need to add more file paths to the project. Go to project settings, and choose the "Directories" tab. Now change it to 'include'. Add in the 'video' folder that is in your project's directory. Mine looked like this:
C:\Documents and Settings\Drew Benton\Desktop\SDL\video. Now try to compile again and you will see that error is gone, but more are still there. Go ahead and add in *all* of the main directories and any "win32" sub directories you find.
You may want to click on the previous item, then choose the directory and add like that so you do not have to re-navigate to the correct directory. You will see what I mean.
Now after all those are done, you will need to do the same thing one more time, for your project's directory. That is so the base header files can be found. After that you should be able to compile, but not link. This is because we need to add in the .c files!
So starting with the audio folder, you will need to add in the .c files, but not all of them. Do not add any thing that has a MMX or m68k in the title, you just want the 'base' versions. You will now do the same thing for the remaning folders, and also add in the .c files in any Win32 subdirectory.
In the joystick/win32, do add in the "SDL_mmjoystick.c".
In the thread/win32, do not add in any of the win_ce files
After all of that is done and you try to compile, there should only be a few linker errors left. To fix some of these you must link in the winmm library. To do so go to the Project Options, Linker, and add in the "Dev-Cpp/lib/libwinmm.a" file.
Now when you try to compile again, you should get two more errors:
[Linker error] undefined reference to `SDL_SetModuleHandle'
[Linker error] undefined reference to `SDL_main'
We happened to miss a directory we needed to add - "video/wincommon". Go ahead and add in those .c files. Don't forget to add in the header files via the project directories. Now we need to link in the opengl files. Here is the new contents of the linker box:
We also happened to miss another directory. Add in "video\windib"'s c files as well as add in the path in the include directories. Compile again and yay, 1 more error:
[Linker error] undefined reference to `SDL_main'
It seems that one file was added that was not supposed to. Remove the file "SDL_win32_main.c" from the workspace and compile again. It should work fine! However upon testing, it does not work [sad], so back to the drawing board. After doing a little looking around the code I figured out we missed more files! Imagine that [lol]. Add in the file "audio/dibaudio.c". Now in the project properties, you will need to add in the line: -DENABLE_WINDIB to the "Compiler Box". Now recompile and it should work again. Upon testing with OpenGL, it worked fine for me but I did not try regular SDL.
Here is the sample program I used:
Now as you may have noticed that you will have to use that WINMAIN styled main function. If you remember regular sdl, it uses a second library the defines the main function. If you want the options, you must make a new project and use that main.c file we had to remove and build that library to use.
I have made my project files avaliable here if you want a working example to start with. You will have to play around with building sdlmain if you really want that. As you can see, building this from scratch is not an easy task (with devcpp at least). Good luck and feel free to ask any questions about this process.
- Drew
[Edited by - Drew_Benton on April 25, 2005 3:47:10 AM]
After you download the source. You will need to extract it.
Now create a new Dev-CPP project. It should be a "C" Dynamic Link Library. I named mine SDL. Close and do not save the 'dllmain.c' and 'dllmain.h' files that popup now.
Copy over the files in the 'src' folder into your new Dev-CPP project's folder. You will also need to copy over the contents of the 'include' folder into the project folder as well. Hit not to any replace dialogs.
Now right click on the workspace and choose add to project. Select all of the .h and .c files in the base directory. Now if you try and compile, it will compain about header files not being found. First, 'SDL_Leaks.h'.
To get around this we need to add more file paths to the project. Go to project settings, and choose the "Directories" tab. Now change it to 'include'. Add in the 'video' folder that is in your project's directory. Mine looked like this:
C:\Documents and Settings\Drew Benton\Desktop\SDL\video. Now try to compile again and you will see that error is gone, but more are still there. Go ahead and add in *all* of the main directories and any "win32" sub directories you find.
You may want to click on the previous item, then choose the directory and add like that so you do not have to re-navigate to the correct directory. You will see what I mean.
Now after all those are done, you will need to do the same thing one more time, for your project's directory. That is so the base header files can be found. After that you should be able to compile, but not link. This is because we need to add in the .c files!
So starting with the audio folder, you will need to add in the .c files, but not all of them. Do not add any thing that has a MMX or m68k in the title, you just want the 'base' versions. You will now do the same thing for the remaning folders, and also add in the .c files in any Win32 subdirectory.
In the joystick/win32, do add in the "SDL_mmjoystick.c".
In the thread/win32, do not add in any of the win_ce files
After all of that is done and you try to compile, there should only be a few linker errors left. To fix some of these you must link in the winmm library. To do so go to the Project Options, Linker, and add in the "Dev-Cpp/lib/libwinmm.a" file.
Now when you try to compile again, you should get two more errors:
[Linker error] undefined reference to `SDL_SetModuleHandle'
[Linker error] undefined reference to `SDL_main'
We happened to miss a directory we needed to add - "video/wincommon". Go ahead and add in those .c files. Don't forget to add in the header files via the project directories. Now we need to link in the opengl files. Here is the new contents of the linker box:
-lwinmm-lopengl32-lglu32-lglaux
We also happened to miss another directory. Add in "video\windib"'s c files as well as add in the path in the include directories. Compile again and yay, 1 more error:
[Linker error] undefined reference to `SDL_main'
It seems that one file was added that was not supposed to. Remove the file "SDL_win32_main.c" from the workspace and compile again. It should work fine! However upon testing, it does not work [sad], so back to the drawing board. After doing a little looking around the code I figured out we missed more files! Imagine that [lol]. Add in the file "audio/dibaudio.c". Now in the project properties, you will need to add in the line: -DENABLE_WINDIB to the "Compiler Box". Now recompile and it should work again. Upon testing with OpenGL, it worked fine for me but I did not try regular SDL.
Here is the sample program I used:
#include <cstdlib>#include <iostream>#include <windows.h>#include "SDL.h"#include "SDL_opengl.h"using namespace std;int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil){ if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) { printf("Unable to init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); if ( NULL == SDL_SetVideoMode( 640, 480, 32, SDL_OPENGL ) ) exit(1); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glFrustum(.5, -.5, -.5 * ((float)480.0f) / 640.0f, .5 * ((float)480.0f) / 640.0f, 1, 50); glMatrixMode(GL_MODELVIEW); bool done = 0; while( !done ) { SDL_Event event; while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_QUIT ) done = 1; if ( event.type == SDL_KEYDOWN ) if ( event.key.keysym.sym == SDLK_ESCAPE ) done = 1; } glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity( ); /****************************************/ glTranslatef( 0, 0, -5 ); glColor3f(0.5f,0.5f,1.0f); glBegin(GL_QUADS); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glEnd(); /****************************************/ SDL_GL_SwapBuffers(); } SDL_Quit(); system("PAUSE"); return EXIT_SUCCESS;}
Now as you may have noticed that you will have to use that WINMAIN styled main function. If you remember regular sdl, it uses a second library the defines the main function. If you want the options, you must make a new project and use that main.c file we had to remove and build that library to use.
I have made my project files avaliable here if you want a working example to start with. You will have to play around with building sdlmain if you really want that. As you can see, building this from scratch is not an easy task (with devcpp at least). Good luck and feel free to ask any questions about this process.
- Drew
[Edited by - Drew_Benton on April 25, 2005 3:47:10 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement