void Init() { window->loadSprite( Mario, ASSET("sprites/mario.png") ) ; window->loadSprite( MouseCursor, ASSET("sprites/mouseCursor.png" ) ) ; // Set the background clearing color to dk blue-gray window->setBackgroundColor( D3DCOLOR_ARGB( 255, 35, 35, 70 ) ) ; // Create a few fonts window->createFont( Fonts::Arial16, "Arial", 16, FW_BOLD, false ) ; window->createFont( Fonts::TimesNewRoman24, "Times New Roman", 24, FW_BOLD, true ) ; window->createButtonSprite( Buttons::ButtonOK, "Start!", new Callback0( 0, OKClicked ), Mario, D3DCOLOR_ARGB( 180, 0, 0, 255 ), Color::White, Color::Green, Fonts::TimesNewRoman24, 350, 250, 180, 55 ) ; window->createTextFieldWithLabel( TextFieldK, TextField::TextEntryType::Numeric, "type something!", "label text", new Callback0( 0, TextFieldModified ), Color::Black, Color::OldLace, Fonts::Arial16, 0, 0, 180, 55 ) ; window->createTextFieldSprite( TextFieldR, (TextField::TextEntryType)(TextField::AlphaLower | TextField::Numeric), "its me!!", new Callback0( 0, tfr ), Sprites::Mario, Color::White, Color::Black, Color::White, Fonts::Arial16, 200, 200, 200, 44 ) ; }
int main(int argc, char** argv){ //Start up SDL and make sure it went ok if (SDL_Init(SDL_INIT_EVERYTHING) != 0){ logSDLError(std::cout, "SDL_Init"); return 1; } //Also need to init SDL_ttf if (TTF_Init() != 0){ logSDLError(std::cout, "TTF_Init"); SDL_Quit(); return 1; } //Setup our window and renderer SDL_Window *window = SDL_CreateWindow("Lesson 6", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if (window == nullptr){ logSDLError(std::cout, "CreateWindow"); TTF_Quit(); SDL_Quit(); return 1; } SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (renderer == nullptr){ logSDLError(std::cout, "CreateRenderer"); cleanup(window); TTF_Quit(); SDL_Quit(); return 1; } //We'll render the string "TTF fonts are cool!" in white //Color is in RGB format SDL_Color color = { 255, 255, 255, 255 }; SDL_Texture *image = renderText("TTF fonts are cool!", ASSET("Lesson6/sample.ttf"), color, 64, renderer); if (image == nullptr){ cleanup(image, renderer, window); TTF_Quit(); SDL_Quit(); return 1; } //Get the texture w/h so we can center it in the screen int iW, iH; SDL_QueryTexture(image, NULL, NULL, &iW, &iH); int x = SCREEN_WIDTH / 2 - iW / 2; int y = SCREEN_HEIGHT / 2 - iH / 2; SDL_Event e; bool quit = false; while (!quit){ //Event Polling while (SDL_PollEvent(&e)){ if (e.type == SDL_QUIT){ quit = true; } if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE){ quit = true; } } SDL_RenderClear(renderer); //We can draw our message as we do any other texture, since it's been //rendered to a texture renderTexture(image, renderer, x, y); SDL_RenderPresent(renderer); } //Clean up cleanup(image, renderer, window); TTF_Quit(); SDL_Quit(); return 0; }
void Init() { // Load sounds #pragma region load up sounds window->loadSound( HumanMusic, ASSET("sounds/Human1.mp3"), FMOD_CREATESTREAM ) ; window->loadSound( TreeWhat, ASSET("sounds/What2.wav") ) ; window->loadSound( ColdArrow1, ASSET("sounds/ColdArrow1.wav") ) ; window->loadSound( ColdArrow2, ASSET("sounds/ColdArrow2.wav") ) ; window->loadSound( ColdArrow3, ASSET("sounds/ColdArrow3.wav") ) ; window->loadSound( NerzuhlWillHaveYourHead, ASSET("sounds/Odpissd3.wav") ) ; window->playSound( TreeWhat ) ; window->loopSound( HumanMusic ) ; // Loop this sound forever #pragma endregion // sprite loading #pragma region load up sprites window->loadSprite( Mario, ASSET("sprites/mario.png") ) ; // Animated sprite window->loadSprite( SixteenCounter, ASSET("sprites/16counter.png"), 0, 32, 32, 16, 0.5f ) ; // other sprites window->loadSprite( Astos, ASSET("sprites/ff/Astos.png") ) ; window->loadSprite( Eye, ASSET("sprites/ff/Eye.png") ) ; window->loadSprite( Garland, ASSET("sprites/ff/Garland.png") ) ; window->loadSprite( Kary, ASSET("sprites/ff/Kary.png") ) ; window->loadSprite( Kraken, ASSET("sprites/ff/Kraken.png") ) ; window->loadSprite( Lich, ASSET("sprites/ff/Lich.png") ) ; window->loadSprite( Phantom, ASSET("sprites/ff/Phantom.png") ) ; window->loadSprite( Pirate, ASSET("sprites/ff/Pirate.png") ) ; window->loadSprite( Chaos, ASSET("sprites/ff/Chaos.gif") ) ; #pragma endregion #pragma region create boxed text sprites // Create boxed text as a sprite. If you do this // to your text before hand, it may run faster than if you // simply running drawBox() and drawString() every call. window->boxedTextSprite( BoxedTextTest, "Some boxed text", D3DCOLOR_ARGB( 255, 255, 0, 0 ), // fg color D3DCOLOR_ARGB( 200, 129, 47, 0 ),// bg color 15 // "padding" around the edges of the text, // try increasing / reducing this value to see // the way it looks ) ; #pragma endregion // Set the background clearing color to dk blue-gray window->setBackgroundColor( D3DCOLOR_ARGB( 255, 35, 35, 70 ) ) ; // Create a few fonts window->createFont( Fonts::Arial8, "Arial", 8, FW_NORMAL, false ) ; window->createFont( Fonts::TimesNewRoman24, "Times New Roman", 24, FW_BOLD, true ) ; // If you don't have this font, you should get Arial instead. window->createFont( Fonts::Elephant16, "Elephant", 16, FW_NORMAL, false ) ; char cwd[260]; GetCurrentDirectoryA( 260, cwd ) ; info( "Current working directory is '%s'", cwd ) ; }