954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SDL image help

#include "includes.h"
#include "constants.h"
#include "functions.h"
int pscore=0,cscore=0,ppaddle=185,cpaddle=185,ballSpeed = 0,cpuPadSpd = 0,frame = 0;
SDL_Surface *screen=NULL,*secondary=NULL,*playerscore=NULL,*cpuscore=NULL,*cpuwin=NULL,*playerwin=NULL; bool gameEnded = false,selectedDiff=false;
TTF_Font *font,*humungo;
SDL_Event e;
//PongBall ball;
void cleanup() {
SDL_Quit();
SDL_EnableUNICODE(0);
exit(0);
}
bool init() {
if (SDL_Init(SDL_INIT_EVERYTHING) == -1) return false;
if (TTF_Init() == -1) return false;
screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,COLORDEPTH,SDL_HWSURFACE);
if (screen == NULL) return false;
SDL_EnableUNICODE(1);
SDL_WM_SetCaption("Pong", NULL);
font = TTF_OpenFont("imagine_font.ttf",72);
humungo = TTF_OpenFont("denmark.ttf",96);
SDL_EnableKeyRepeat(50, 5);
cpuwin = TTF_RenderText_Blended(humungo,"You lose!",createColor(255,255,255));
playerwin = TTF_RenderText_Blended(humungo,"You win!",createColor(255,255,255));
return true;
}

int main (int argc, char *argv[]) {
if (!init()) return 1;
fillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,0,0,0);
secondary = loadImage("c0v3r.png");
applySurface(0,0,secondary,screen);
SDL_Flip(screen);
SDL_Delay(2500);
cleanup();
return 0;
}

epicbeast9022
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Well, you show your code (please indent - it will be easier to analyze), but don't say anything about what is your problem.

rubberman
Posting Virtuoso
1,564 posts since Mar 2010
Reputation Points: 277
Solved Threads: 179
 

Okay - I was in a hurry
Here's my code:

int main (int argc, char *argv[]) {
if (!init()) return 1;
fillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,0,0,0);
secondary = loadImage("c0v3r.png");
applySurface(0,0,secondary,screen);
SDL_Flip(screen);
SDL_Delay(2500);
cleanup();
return 0;
}
int main (int argc, char *argv[]) {
if (!init()) return 1;
fillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,0,0,0); // From 0,0 to SCREEN_WIDTH,SCREEN_HEIGHT with RGB 0,0,0
secondary = loadImage("c0v3r.png");
applySurface(0,0,secondary,screen);
SDL_Flip(screen);
SDL_Delay(2500);
cleanup();
return 0;
}

I'm trying to make it display the image but all I get is a black screen.

epicbeast9022
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

I made a really stupid mistake
My image is in 32 bit color but I only set 8 bit color.
When I change

COLORDEPTH


to 32 it works!!

epicbeast9022
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

I notice in your SDL_SetVideoMode() call, you are using the SDL_HWSURFACE flag which forces the video rendering in the video hardware memory. Have you tried SDL_SWSURFACE, using system memory instead? It may be that your video hardware doesn't deal with this well.

Never mind! I see you have already solved this. Good for you.

rubberman
Posting Virtuoso
1,564 posts since Mar 2010
Reputation Points: 277
Solved Threads: 179
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: