Я пытался заставить этот код работать над разными классами, он имеет пустое окно и сразу же закрывается.Попытка заставить код работать над классами
main.cpp
//The Headers
#include "SDL_SCREEN.h"
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
//The event structure
SDL_Event event;
int main (int argc, char* args[]){
printf("START");
//The quit flag
bool quit = false;
//The Surface to be displayed
SDL_Surface* dis = NULL;
//The Screen Surface
SDL_Surface* screen = NULL;
//The screen
SDL_SCREEN screen_sdl;
if (screen_sdl.init("TEST", screen) == false)
{
return 1;
}
dis = screen_sdl.load_image("a.png");
screen_sdl.apply_surface(0, 0, dis, screen, NULL);
if (SDL_Flip (screen) == -1)
{
return 1;
}
while (quit == false)
{
//While there are events to handle
while (SDL_PollEvent(&event))
{
//if the user has xed out the window
if (event.type == SDL_QUIT)
{
//Quit the program
quit = true;
}
}
}
screen_sdl.clean_up(dis, screen);
SDL_Quit();
}
SDL_SCREEN.h
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
class SDL_SCREEN{
public:
SDL_Surface *load_image(char*);
void apply_surface(int, int, SDL_Surface*, SDL_Surface*, SDL_Rect*);
bool init(char*, SDL_Surface*);
void clean_up(SDL_Surface*, SDL_Surface*);
void flip_screen (SDL_Surface* screen){
if (SDL_Flip (screen) == -1)
{
printf("BLAH");
}
}
};
SDL_SCREEN.cc
//The Headers
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL_SCREEN.h"
#include <stdio.h>
//Screen atrabutes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
SDL_Surface *SDL_SCREEN::load_image (char *filename)
{
printf("LOADING");
//the image thats loaded
SDL_Surface* loadedImage = NULL;
//The optimized image
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = IMG_Load(filename);
if (loadedImage != NULL)
{
printf("Loaded");
//Create the optimized image
optimizedImage = SDL_DisplayFormat(loadedImage);
//Free the old surface
SDL_FreeSurface(loadedImage);
//If the surface was optimized
if (optimizedImage != NULL)
{
printf(" OPTIMIZED");
//Color key the surface
SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB(optimizedImage->format, 0, 0xFF, 0xFF));
}
}
//return the optimized image
return optimizedImage;
}
void SDL_SCREEN::apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL)
{
//holds offsets
SDL_Rect offset;
//get offsets
offset.x = x;
offset.y = y;
//blit
SDL_BlitSurface(source, clip, destination, &offset);
}
void SDL_SCREEN::clean_up(SDL_Surface* to_clean, SDL_Surface* screen )
{
//Free the surfaces
SDL_FreeSurface(to_clean);
SDL_FreeSurface(screen);
}
bool SDL_SCREEN::init (char *Caption, SDL_Surface *screen)
{
//Initialize all SDL subsystems
if (SDL_Init(SDL_INIT_EVERYTHING == -1))
{
return false;
}
//set ut the screen
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
//if there was an error setting up the screen
if(screen == NULL)
{
return false;
}
//set up the window caption
SDL_WM_SetCaption(Caption, NULL);
return true;
}
Пожалуйста, включите соответствующий код в форме [короткого, самодостаточного правильного примера] (http://sscce.org) в вашем вопросе. Не только ссылайтесь на него. Страница, с которой вы связались, исчезнет, и ваш вопрос станет бесполезным для других. – Oswald
Извините, я новичок в этом :(и не хочу тратить следующие несколько минут на новый код – icodenosleep
Лучше вы потратите эти несколько минут, чем все, кто пытается ответить на ваш вопрос. – Oswald