According to its news site, SDL 2 is now released:
http://www.libsdl.org/news.php
That includes the main library as well as SDL_image and SDL_mixer.
Evropi {l Wrote}:The title is accurate, but the content is a bit of a misnomer... this is a release candidate. This means that this is not considered very stable, but certainly, it is close to a release and no new features will be added. Lots of games (and other applications) are using it already though, so it won't be long till it hits stable.
#include "SDL.h"
#include "SDL_ttf.h"
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char** argv) {
// SDL vars...
SDL_Window *window = nullptr;
SDL_Renderer *renderer = nullptr;
// Setting up SDL...
if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
cout << SDL_GetError() << endl;
return 1;
}
// ...create the window...
window = SDL_CreateWindow("Input-Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
if (window == nullptr) {
cout << SDL_GetError() << endl;
return 1;
}
// ...and the renderer.
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (renderer == nullptr) {
cout << SDL_GetError() << endl;
return 1;
}
// Set up TTF.
if (TTF_Init() != 0) {
string msg = TTF_GetError();
cout << msg << endl;
}
// Background
SDL_Rect backgroundRect;
backgroundRect.x = 0;
backgroundRect.y = 0;
backgroundRect.w = 640;
backgroundRect.h = 480;
// Load the font.
TTF_Font *font = TTF_OpenFont("VeraMono.ttf", 18);
if (font == nullptr) {
string msg = TTF_GetError();
cout << msg << endl;
return 1;
}
SDL_Color fontColor = {255,255,255,255};
SDL_Surface *fontSurface = TTF_RenderText_Blended(font, "Press c to open console, Esc to abort and Enter to confirm.", fontColor);
SDL_Texture *fontTexture = SDL_CreateTextureFromSurface(renderer, fontSurface);
// The main loop.
bool quit = false;
SDL_Event event;
while (!quit) {
// Events and updates...
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT)
quit = true;
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_q) {
quit = true;
}
}
}
// Draw stuff.
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 51, 130, 152, 0);
SDL_RenderFillRect(renderer, &backgroundRect);
SDL_RenderCopy(renderer, fontTexture, nullptr, nullptr);
SDL_RenderPresent(renderer);
SDL_Delay(10);
}
TTF_CloseFont(font);
SDL_DestroyTexture(fontTexture);
SDL_FreeSurface(fontSurface);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
TTF_Quit();
SDL_Quit();
return 0;
}
Sauer2 {l Wrote}:It's stuff like this which makes me wish for the simple gcc toolchain.
Users browsing this forum: No registered users and 1 guest