Size: 1994
Comment: Corrected includes.
|
Size: 1969
Comment: Changed example to be more compatible with C (was C++).
|
Deletions are marked like this. | Additions are marked like this. |
Line 24: | Line 24: |
#include <string> using std::string; |
|
Line 30: | Line 27: |
SDL_Init(SDL_INIT_VIDEO); // Init SDL2 // Create a window. SDL_Window *window = SDL_CreateWindow( "This will surely be overwritten", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_RESIZABLE ); string titles[] = { // just for fun, let's make the title animate like a marquee and annoy users |
SDL_Window *window; SDL_Event e; const char *titles[] = { // just for fun, let's make the title animate like a marquee and annoy users |
Line 43: | Line 36: |
SDL_Init(SDL_INIT_VIDEO); // Init SDL2 |
|
Line 44: | Line 39: |
// Create a window. window = SDL_CreateWindow( "This will surely be overwritten", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_RESIZABLE ); |
|
Line 45: | Line 45: |
for(SDL_Event e; e.type!=SDL_QUIT&&e.type!=SDL_KEYDOWN; SDL_PollEvent(&e)){ | for( ; e.type!=SDL_QUIT&&e.type!=SDL_KEYDOWN; SDL_PollEvent(&e)){ |
Line 47: | Line 47: |
Line 49: | Line 49: |
SDL_SetWindowTitle(window, titles[i].c_str()); // loop through the if(++i >= sizeof(titles)/sizeof(string)) i = 0; // array of titles |
SDL_SetWindowTitle(window, titles[i]); // loop through the if(++i >= sizeof(titles)/sizeof(titles[0])) i = 0; // array of titles |
Line 52: | Line 52: |
SDL_SetWindowTitle
Use this function to set the title of a window.
Syntax
void SDL_SetWindowTitle(SDL_Window* window,
const char* title)
Function Parameters
window |
the window to change |
title |
the desired window title in UTF-8 format |
Code Examples
// dynamically setting a window title
#include "SDL.h"
int main(int argc, char* argv[]){
SDL_Window *window;
SDL_Event e;
const char *titles[] = { // just for fun, let's make the title animate like a marquee and annoy users
"t", "thi", "this w", "this win", "this windo", "this window's", "this window's ti", "this window's title",
"chis window's title is", "chih window's title is ", "chih wandnw's title is ", "c h wandnw'g title is ",
"c h a nw'g titln is ", "c h a n g i n ig ", "c h a n g i n g!", "",
"c h a n g i n g!", "", "c h a n g i n g!", "c h a n g i n g!"
};
SDL_Init(SDL_INIT_VIDEO); // Init SDL2
// Create a window.
window = SDL_CreateWindow(
"This will surely be overwritten", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_RESIZABLE
);
// Enter the main loop. Press any key or hit the x to exit.
for( ; e.type!=SDL_QUIT&&e.type!=SDL_KEYDOWN; SDL_PollEvent(&e)){
static int i = 0, t = 0;
if(!(++t%9)){ // every 9th frame...
SDL_SetWindowTitle(window, titles[i]); // loop through the
if(++i >= sizeof(titles)/sizeof(titles[0])) i = 0; // array of titles
}
SDL_Delay(10);
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
Remarks
You can add useful comments here