LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-22-2005, 09:04 PM   #1
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889
Blog Entries: 1

Rep: Reputation: 30
SDL Image problem.. how do I add image?


--EDIT--
My first question was answered... I have one more about this piece of code the 2nd or 3rd post down.

I have been reading the SDL tutorials and this is what I have from them...

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <SDL/SDL.h>
using namespace std;

SDL_Surface *screen;

int main(int nNumberofArgs, char* pszArgs[])
{

/* Initialize the SDL library */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
"Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}

/* Clean up on exit */
atexit(SDL_Quit);

/*
* Initialize the display in a 640x480 8-bit palettized mode,
* requesting a software surface
*/
screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
SDL_GetError());
exit(1);
}
}
void display_bmp(char *file_name)
{
SDL_Surface *image;

/* Load the BMP file into a surface */
image = SDL_LoadBMP(file_name);
if (image == NULL) {
fprintf(stderr, "Couldn't load %s: %s\n", file_name, SDL_GetError());
return;
}

/*
* Palettized screen modes will have a default palette (a standard
* 8*8*4 colour cube), but if the image is palettized as well we can
* use that palette for a nicer colour matching
*/
if (image->format->palette && screen->format->palette) {
SDL_SetColors(screen, image->format->palette->colors, 0,
image->format->palette->ncolors);
}

/* Blit onto the screen surface */
if(SDL_BlitSurface(image, NULL, screen, NULL) < 0)
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());

SDL_UpdateRect(screen, 0, 0, image->w, image->h);

/* Free the allocated BMP surface */
SDL_FreeSurface(image);

atexit(SDL_Quit);

return 0;
}

... I get this error...

anyone@george's:~$ g++ -s sdl2.cpp -o sdl2 `sdl-config --libs --cflags`
sdl2.cpp: In function `void display_bmp(char*)':
sdl2.cpp:65: error: return-statement with a value, in function declared with a
void return type

... from what I understand it has to do with the return type. I did the following...

return 1;
return (void);
and
return display_bmp;

... I don't totaly understand the problem. I have to return something, with a void return type obviously, but I don't quite understand what its asking for. Could someone clarify what the return is exactly? And maby hint me in the direction of what it wants me to return, just to make it fun, so I can figure out how to fix it. (with a little push in the right direction of course) Thanx in advance!

Last edited by RHLinuxGUY; 07-22-2005 at 11:37 PM.
 
Old 07-22-2005, 11:00 PM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
Try just:

return;

The problem is that your function prototype is void, which means it doesn't return anything, but yet you are trying to return the value 0...
 
Old 07-22-2005, 11:35 PM   #3
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889
Blog Entries: 1

Original Poster
Rep: Reputation: 30
hey thanx it worked. One last question. How do I add an image to my code...

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <SDL/SDL.h>
using namespace std;

SDL_Surface *screen;

int main(int nNumberofArgs, char* pszArgs[])
{

/* Initialize the SDL library */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
"Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}

/* Clean up on exit */
atexit(SDL_Quit);

/*
* Initialize the display in a 640x480 8-bit palettized mode,
* requesting a software surface
*/
screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
SDL_GetError());
exit(1);
}
}
void display_bmp(char *file_name)
{
SDL_Surface *image;

/* Load the BMP file into a surface */
image = SDL_LoadBMP(file_name);
if (image == NULL) {
fprintf(stderr, "Couldn't load %s: %s\n", file_name, SDL_GetError());
return;
}

/*
* Palettized screen modes will have a default palette (a standard
* 8*8*4 colour cube), but if the image is palettized as well we can
* use that palette for a nicer colour matching
*/
if (image->format->palette && screen->format->palette) {
SDL_SetColors(screen, image->format->palette->colors, 0,
image->format->palette->ncolors);
}

/* Blit onto the screen surface */
if(SDL_BlitSurface(image, NULL, screen, NULL) < 0)
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());

SDL_UpdateRect(screen, 0, 0, image->w, image->h);

/* Free the allocated BMP surface */
SDL_FreeSurface(image);

atexit(SDL_Quit);

return;
}

??? I put in the file name where "file_name" it located, but it doesn't show anything??? Any ideas?
 
Old 07-23-2005, 03:36 AM   #4
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,548

Rep: Reputation: 120Reputation: 120
The display_bmp(char *file_name) function is not executed
as you don't call it in your main() function
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a good Linux ISO image to put on a 250 MB mini-CD tvisher Linux - Distributions 8 07-29-2005 10:54 AM
Trying to program an SDL application but cannot find the SDL.h file:SuSE 9.2&KDevelop pujolasdf Linux - Newbie 4 03-13-2005 07:50 AM
would like to make my own image and put it at my text screen login....... deepsix General 1 02-08-2005 11:50 PM
sdl .raw image-based map loading elvee Programming 2 10-09-2004 02:03 AM
How make disk image and put it on my new hdd jimdaworm Linux - Hardware 5 12-16-2003 11:58 AM


All times are GMT -5. The time now is 01:43 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration