1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
//==============================================================================
#include "CApp.h"
#include "SDL2/SDL_image.h"
//==============================================================================
void 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 );
}
bool CApp::OnInit()
{
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
printf("failed to initi\n");
printf("SDL_Init failed: %s\n", SDL_GetError());
return false;
}
window = SDL_CreateWindow("Open Multiplayer RPG",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
WWIDTH, WHEIGHT,
SDL_WINDOW_RESIZABLE );
Surf_Display = SDL_CreateRenderer(window, -1, SDL_RENDERER_TARGETTEXTURE|SDL_RENDERER_PRESENTVSYNC );
/*
if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
return false;
}
if((Surf_Display = SDL_SetVideoMode(WWIDTH, WHEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL) {
return false;
}
*/
if(CArea::AreaControl.OnLoad("assets/maps/1.area", Surf_Display ) == false) {
printf("failed to Load Map");
return false;
}
//SDL_EnableKeyRepeat(1, SDL_DEFAULT_REPEAT_INTERVAL / 3);
if(Player.OnLoad("./assets/onionknight.png", 32, 52, 8, Surf_Display) == false) {
printf("failed to Load Onion Knight");
return false;
}
if(TTF_Init()==-1) {
printf("TTF_Init: %s\n", TTF_GetError());
exit(2);
}
if(Weapon.OnLoad("./assets/Icebrand.png", 25,25, 8, Surf_Display) == false) {
printf("failed to Load Icebrand");
return false;
}
//txt.Draw("./lazy.ttf","olá",1000,Surf_Display);
CEntity::EntityList.push_back(&Player);
//CEntity::EntityList.push_back(&Weapon);
//CLoginScreen::LOADIMAGE.OnLoad("b.png",32,52,8,Surf_Display);
CCamera::CameraControl.TargetMode = TARGET_MODE_CENTER;
CCamera::CameraControl.SetTarget(&Player.X, &Player.Y);
SDL_Surface *message = NULL;
SDL_Color textColor = {255,255,255};
SDL_Rect rect;
SDL_Texture *bitmapTex = NULL;
SDL_Surface *bitmapSurface = NULL;
rect.x=0;
rect.y=0;
rect.w=100;
rect.h=100;
font = TTF_OpenFont( "./font.ttf", 50 );
if(!font) {
printf("TTF_OpenFont: %s\n", TTF_GetError());
// handle error
}
message = TTF_RenderText_Solid( font, "aaaaaaaaaaaaaaaaaaaaaaa", textColor );
SDL_Surface *screen;
screen = SDL_GetWindowSurface(window);
SDL_BlitSurface(message, NULL, screen, &rect);
SDL_Texture* atex= SDL_CreateTextureFromSurface(Surf_Display,screen);
//bitmapSurface = SDL_LoadBMP("./assets/onionknight.png");
// bitmapTex = SDL_CreateTextureFromSurface(Surf_Display, bitmapSurface);
SDL_RenderCopy(Surf_Display, atex, NULL, NULL);
apply_surface( 0, 0, message, screen );
//SDL_Flip( screen );
SDL_UpdateWindowSurface(window);
return true;
}
//==============================================================================
|