quadratisches SDL-Fenster öffnet sich
This commit is contained in:
parent
6b29f1360f
commit
668860a6a0
@ -5,4 +5,6 @@
|
|||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
void renderGame();
|
void renderGame();
|
||||||
//erstellt aus Spielfeldstruktur die graphische Anzeige mit SDL-Framework
|
//erstellt aus Spielfeldstruktur die graphische Anzeige mit SDL-Framework
|
||||||
|
|
||||||
|
int CreateSDLWindow();
|
28
src/main.cpp
28
src/main.cpp
@ -1,9 +1,13 @@
|
|||||||
#include "SDL.h"
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "food.h"
|
#include "food.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C"{
|
||||||
|
#include "render.h"
|
||||||
|
}
|
||||||
|
|
||||||
//initialize SDL window
|
//initialize SDL window
|
||||||
//ruft showStartScreen
|
//ruft showStartScreen
|
||||||
//initialize game
|
//initialize game
|
||||||
@ -13,26 +17,6 @@ extern "C" {
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
CreateSDLWindow();
|
||||||
|
|
||||||
SDL_Window *window = SDL_CreateWindow(
|
|
||||||
"SDL2Test",
|
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
|
||||||
640,
|
|
||||||
480,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
|
|
||||||
SDL_Delay(1000);
|
|
||||||
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
SDL_Quit();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
34
src/render.c
34
src/render.c
@ -1,8 +1,8 @@
|
|||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
#include "SDL.h"
|
||||||
|
|
||||||
|
void renderGame(){}
|
||||||
|
|
||||||
void renderGame(){
|
|
||||||
//note: maybe re-use renderGameToArray() from map.h?
|
|
||||||
//e.g. as used in map.c for printMap()
|
|
||||||
/*SDL_Event event;
|
/*SDL_Event event;
|
||||||
SDL_Window* window = NULL;
|
SDL_Window* window = NULL;
|
||||||
SDL_Surface* surface = NULL;
|
SDL_Surface* surface = NULL;
|
||||||
@ -47,18 +47,8 @@ void renderGame(){
|
|||||||
|
|
||||||
SDL_DestroyWindow(window);*/
|
SDL_DestroyWindow(window);*/
|
||||||
|
|
||||||
/* SDL_Init(SDL_INIT_VIDEO);
|
|
||||||
|
|
||||||
SDL_Window* window = SDL_CreateWindow
|
int CreateSDLWindow(){
|
||||||
("Ein SDL2-Fenster", // Name des Fensters
|
|
||||||
10, 25, // Koordinaten auf dem Bildschirm in Pixeln, ausgehend von links oben
|
|
||||||
840, 840, // Breite und Höhe des Fenster in Pixeln
|
|
||||||
SDL_WINDOW_OPENGL);
|
|
||||||
|
|
||||||
SDL_Delay(30000); // Das Fenster bleibt drei Sekunden
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
SDL_Quit();
|
|
||||||
*/
|
|
||||||
// Initialisiere SDL
|
// Initialisiere SDL
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||||
printf("SDL konnte nicht initialisiert werden! SDL_Error: %s\n", SDL_GetError());
|
printf("SDL konnte nicht initialisiert werden! SDL_Error: %s\n", SDL_GetError());
|
||||||
@ -66,24 +56,20 @@ void renderGame(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Erstelle ein SDL-Fenster
|
// Erstelle ein SDL-Fenster
|
||||||
SDL_Window* window = SDL_CreateWindow("Ein SDL2-Fenster", 10, 25, 640, 480, SDL_WINDOW_OPENGL);
|
SDL_Window* window = SDL_CreateWindow("Snake", 350, 50, 800, 800, SDL_WINDOW_OPENGL);
|
||||||
if (window == NULL) {
|
if (window == NULL) {
|
||||||
printf("Fenster konnte nicht erstellt werden! SDL_Error: %s\n", SDL_GetError());
|
printf("Fenster konnte nicht erstellt werden! SDL_Error: %s\n", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warte drei Sekunden
|
// Warte drei Sekunden
|
||||||
SDL_Delay(3000);
|
SDL_Delay(10000);
|
||||||
|
|
||||||
// Ändere die Fenstergröße auf 840x840
|
|
||||||
SDL_SetWindowSize(window, 840, 840);
|
|
||||||
|
|
||||||
// Warte drei Sekunden
|
|
||||||
SDL_Delay(3000);
|
|
||||||
|
|
||||||
// Zerstöre das Fenster und beende SDL
|
// Zerstöre das Fenster und beende SDL
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user