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
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
#include "C_SDL2.hpp" int main(int arkc, char* arkv[]) { C_SDL2* Spiel = new C_SDL2("Du Peniskopf !", 800, 600, false); Spiel->C_SDL2_Starten(); delete Spiel; return(0); } |
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 |
#ifndef C_SDL2_HPP #define C_SDL2_HPP #include<SDL.h> #include<iostream> #include"C_SDL2_Texture.hpp" class C_SDL2 { public: C_SDL2(const char* c_chFenstertitel, const int c_iBildbreite, const int c_iBildhoehe, bool bVollbild); ~C_SDL2(); void C_SDL2_Starten(); private: int mc_iBildschirmbreite; int mc_iBildschirmhoehe; bool m_bSpielschleife; SDL_Event mS_C_SDL2_Eingabe; SDL_Window* mz_C_SDL2_Fenster; SDL_Renderer* mz_C_SDL2_Bildschirmausgabe; }; #endif |
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
#include "C_SDL2.hpp" C_SDL2::C_SDL2(const char * c_chFenstertitel, const int c_iBildbreite, const int c_iBildhoehe, bool b_Vollbild) { mc_iBildschirmbreite = c_iBildbreite; mc_iBildschirmhoehe = c_iBildhoehe; m_bSpielschleife = false; if (b_Vollbild == false) { if (SDL_Init(SDL_INIT_VIDEO) != 0) { std::cerr << "SDL2 konnte nicht initialisiert werden ! " << SDL_GetError() << std::endl; exit(-1); } atexit(SDL_Quit); mz_C_SDL2_Fenster = SDL_CreateWindow(c_chFenstertitel, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, c_iBildbreite, c_iBildhoehe, SDL_WINDOW_OPENGL /* | SDL_WINDOW_FULLSCREEN*/); if (mz_C_SDL2_Fenster == NULL) { std::cerr << "SDL2 Fenster konnte nicht initialisiert werden ! " << SDL_GetError() << std::endl; exit(-1); } mz_C_SDL2_Bildschirmausgabe = SDL_CreateRenderer(mz_C_SDL2_Fenster, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); if (mz_C_SDL2_Bildschirmausgabe == NULL) { std::cerr << "SDL2 Bildschirmausgabe konnte nicht initialisiert werden ! " << SDL_GetError() << std::endl; exit(-1); } } if (b_Vollbild == true) { if (SDL_Init(SDL_INIT_VIDEO) != 0) { std::cerr << "SDL2 konnte nicht initialisiert werden ! " << SDL_GetError() << std::endl; exit(-1); } atexit(SDL_Quit); mz_C_SDL2_Fenster = SDL_CreateWindow(c_chFenstertitel, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, c_iBildbreite, c_iBildhoehe, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN); if (mz_C_SDL2_Fenster == NULL) { std::cerr << "SDL2 Fenster konnte nicht initialisiert werden ! " << SDL_GetError() << std::endl; exit(-1); } mz_C_SDL2_Bildschirmausgabe = SDL_CreateRenderer(mz_C_SDL2_Fenster, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); if (mz_C_SDL2_Bildschirmausgabe == NULL) { std::cerr << "SDL2 Bildschirmausgabe konnte nicht initialisiert werden ! " << SDL_GetError() << std::endl; exit(-1); } } } C_SDL2::~C_SDL2() { SDL_DestroyRenderer(mz_C_SDL2_Bildschirmausgabe); SDL_DestroyWindow(mz_C_SDL2_Fenster); SDL_Quit(); } void C_SDL2::C_SDL2_Starten() { // feuerball.png laden C_SDL2_Texture* z_C_SDL2_FEUERBALL_PNG = new C_SDL2_Texture(mz_C_SDL2_Bildschirmausgabe, "data/feuerball.png"); if (z_C_SDL2_FEUERBALL_PNG == NULL) { std::cout << "SDL2 Bild : feuerball.png konnte nicht initialisiert und geladen werden ! " << IMG_GetError() << std::endl; exit(-1); } //////////////////////////////////////////////////////////// while (!m_bSpielschleife) { while (SDL_PollEvent(&mS_C_SDL2_Eingabe)) { if (mS_C_SDL2_Eingabe.type == SDL_QUIT) { m_bSpielschleife = true; } if(mS_C_SDL2_Eingabe.type == SDL_KEYDOWN) { m_bSpielschleife = true; } if (mS_C_SDL2_Eingabe.type == SDL_MOUSEBUTTONDOWN) { m_bSpielschleife = true; } } ///////////////////////////////////// // // Renderer/Hintergrund weiß färben SDL_SetRenderDrawColor(mz_C_SDL2_Bildschirmausgabe, 0xFF, 0xFF, 0xFF, 0xFF); ///////////////////////////////////// // // Renderer frei machen von alten Müll SDL_RenderClear(mz_C_SDL2_Bildschirmausgabe); z_C_SDL2_FEUERBALL_PNG->C_SDL2_Draw(33, 33, 0, 0); //////////////////////////////////// // // Hier wird Gezeichnet :) SDL_RenderPresent(mz_C_SDL2_Bildschirmausgabe); //////////////////////////////////// // // Hier noch ne kurze Pause von 3s ! } // Alles was so nach dem Programm weg soll wird hier aufgeräumt :P // delete z_C_SDL2_FEUERBALL_PNG; } |
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 |
#ifndef C_SDL2_TEXTURE_HPP #define C_SDL2_TEXTURE_HPP #include<SDL.h> #include<SDL_image.h> #include<iostream> #include<string> class C_SDL2_Texture { public: C_SDL2_Texture(SDL_Renderer* z_C_CSDL2_Bildschirmausgabe, std::string s_C_CSDL2_Bilddateipfad); ~C_SDL2_Texture(); void C_SDL2_Draw(int iBildbreite, int iBildhoehe, int iX_Position, int iY_Position); private: SDL_Renderer* mz_C_SDL2_Bildschirmausgabe; SDL_Texture* mz_C_CSDL2_Texture; SDL_Rect mS_C_SDL2_B_H_X_Y; }; #endif |
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 |
#include "C_SDL2_Texture.hpp" C_SDL2_Texture::C_SDL2_Texture(SDL_Renderer* z_C_CSDL2_Bildschirmausgabe, std::string s_C_CSDL2_Bilddateipfad) { std::string s_C_SDL2_Bilddateipfad = SDL_GetBasePath(); s_C_SDL2_Bilddateipfad += s_C_CSDL2_Bilddateipfad; mz_C_CSDL2_Texture = IMG_LoadTexture(z_C_CSDL2_Bildschirmausgabe, s_C_CSDL2_Bilddateipfad.c_str()); if (mz_C_CSDL2_Texture == NULL) { std::cerr << "SDL2 " << s_C_SDL2_Bilddateipfad << " konnte nicht initialisiert und geladen werden ! " << IMG_GetError() << std::endl; exit(-1); } this->mz_C_SDL2_Bildschirmausgabe = z_C_CSDL2_Bildschirmausgabe; mS_C_SDL2_B_H_X_Y.x = 0; mS_C_SDL2_B_H_X_Y.y = 0; mS_C_SDL2_B_H_X_Y.w = 0; mS_C_SDL2_B_H_X_Y.h = 0; SDL_QueryTexture(mz_C_CSDL2_Texture, NULL, NULL, &mS_C_SDL2_B_H_X_Y.w, &mS_C_SDL2_B_H_X_Y.h); } C_SDL2_Texture::~C_SDL2_Texture() { SDL_DestroyTexture(mz_C_CSDL2_Texture); SDL_DestroyRenderer(mz_C_SDL2_Bildschirmausgabe); IMG_Quit(); } void C_SDL2_Texture::C_SDL2_Draw(int iBildbreite, int iBildhoehe, int iX_Position, int iY_Position) { mS_C_SDL2_B_H_X_Y.x = iX_Position; mS_C_SDL2_B_H_X_Y.y = iY_Position; mS_C_SDL2_B_H_X_Y.w = iBildbreite; mS_C_SDL2_B_H_X_Y.h = iBildhoehe; SDL_RenderCopy(mz_C_SDL2_Bildschirmausgabe, mz_C_CSDL2_Texture, NULL, &mS_C_SDL2_B_H_X_Y); } |
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »schepses« (19.12.2017, 17:28)
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »schepses« (19.12.2017, 17:25)
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige