#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;
}

Recommended Answers

All 4 Replies

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

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.

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!!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.