Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

21.12.2014, 13:26

SDL richtig installieren + example: ttf+ int und sound

Hallo - ich hab mich die tage mal schlau gemacht und möchte euch für zukünftige Projekte zeigen wie man SDL2 (2.0.0.3)
richtig aufsetzt...

Setup SDL 2.0.0.3


first include the new platform.h to SDL2/include
copy sdl32.dll from SDL2/bin to your exe folder

include the sdl path in c++
lib the sdl path in c++

Linker: -lmingw32 -lSDL2main -lSDL2

__________________________________________________


Setup TTF
-------------------------
download: SDL2_ttf-devel-2.0.0-VC

-unpack X86 folder

include SDL_TTF.h to SDL2/include
include SDL_TTF.lib to SDL2/lib
include all DLLs from x86/ttf/lib to your exe folder

add linker: -lSDL2_ttf


Setup Mixer
-------------------------
download: SDL2_mixer-devel-2.0.12-VC

- unpack X86 folder

include SDL_mixer.h to SDL2/include
include SDL_mixer.lib to SDL2/lib
include all DLLs from x86/mixer/lib to your exe folder

add linker -lSDL2_mixer

_____________________________________________________

have fun ;)

Bitte mal unter wichtig oder so abspeichern ... :D


TTF + int sample: (für score ect..)

C-/C++-Quelltext

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
#include <SDL.h>
#include <SDL_ttf.h>

#include <iostream>
#include <sstream>

#define __USE_C99_MATH
#include <stdbool.h>

int number = 0;

SDL_Surface* ScreenSurface =NULL;
SDL_Surface* window = NULL;
SDL_Surface* Background = NULL;

SDL_Surface *text1 = NULL;
SDL_Surface *text2 = NULL;

int main(int argc, char** argv)
{
 SDL_Init(SDL_INIT_VIDEO);

 SDL_Window * window = SDL_CreateWindow("SDL TTF + int Example",
 SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,   800, 600, 0);

 TTF_Init();

 TTF_Font *font = TTF_OpenFont("calibri.ttf",20);
 SDL_Color color = {255, 204, 0, 255};
 text1 = TTF_RenderText_Blended(font,"Score:",color);

 ScreenSurface = SDL_GetWindowSurface(window);

 Background= SDL_LoadBMP("background.bmp");

 SDL_Event event;
 bool quit;

 //GAME LOOP
 while (quit == false)
 {
  while (SDL_PollEvent(&event))
 {
  switch(event.type)
  {
   case SDL_QUIT:
   quit= true;
   break;
  }
 }
  //draw background
  SDL_BlitSurface(Background, NULL, ScreenSurface, NULL);

  SDL_Rect textPosition;
  textPosition.x = 5;
  textPosition.y = 5;

  //draw "Score: " on screen
  SDL_BlitSurface(text1, NULL, ScreenSurface,  &textPosition);

  std::stringstream Text;
  Text.clear();
  Text.str( "" );
  Text << number;
  
  //draw int to string
  text2 = TTF_RenderText_Blended(font, Text.str().c_str(),color);

  SDL_Rect textPosition_int;
  textPosition_int.x = 70;
  textPosition_int.y = 5;
  
  draw int on screen
  SDL_BlitSurface(text2, NULL, ScreenSurface,  &textPosition_int);

  number++;

  SDL_UpdateWindowSurface(window);
 }

 SDL_DestroyWindow(window);
 SDL_FreeSurface(Background);


 TTF_Quit();
 SDL_Quit();
}



SDL Mixer (sound)

C-/C++-Quelltext

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
#include <SDL.h>
#include <SDL_mixer.h>


#define __USE_C99_MATH
#include <stdbool.h>


SDL_Surface* ScreenSurface =NULL;
SDL_Surface* window = NULL;
SDL_Surface* Background = NULL;

int main(int argc, char** argv)
{
 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);

 SDL_Window * window = SDL_CreateWindow("SDL Example",
 SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,   800, 600, 0);

 Mix_OpenAudio(44100,MIX_DEFAULT_FORMAT,2,2048);

 Mix_Chunk *sound1 = Mix_LoadWAV("LASER.wav");

 ScreenSurface = SDL_GetWindowSurface(window);

 Background= SDL_LoadBMP("background.bmp");

 Mix_PlayChannel(-1,sound1,0);

 SDL_Event event;
 bool quit;

 //GAME LOOP
 while (quit == false)
 {
  while (SDL_PollEvent(&event))
 {
  switch(event.type)
  {
   case SDL_QUIT:
   quit= true;
   break;
  }
 }

  SDL_BlitSurface(Background, NULL, ScreenSurface, NULL);


  SDL_UpdateWindowSurface(window);
 }

 SDL_DestroyWindow(window);
 SDL_FreeSurface(Background);
 Mix_FreeChunk(sound1);

 Mix_Quit();
 SDL_Quit();
}

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »TrikkieMikkie« (21.12.2014, 14:31)


BlueCobold

Community-Fossil

Beiträge: 10 738

Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer

  • Private Nachricht senden

2

21.12.2014, 13:47

Bitte öffne Topics nicht doppelt. Das hilft niemandem.

SDL2 (2.0.0.3) richtig installieren + 2 example codes (ttf + int) und sound
Teamleiter von Rickety Racquet (ehemals das "Foren-Projekt") und von Marble Theory

Willkommen auf SPPRO, auch dir wird man zu Unity oder zur Unreal-Engine raten, ganz bestimmt.[/Sarkasmus]