mirror of
https://github.com/ysoftdevs/cpp-examples.git
synced 2026-01-18 01:26:59 +01:00
update SDL2 video example with Gradle build
This commit is contained in:
@@ -178,7 +178,7 @@ It is possible to generate project for Visual Studio:
|
|||||||
|
|
||||||
Compiled binary will be stored in:
|
Compiled binary will be stored in:
|
||||||
|
|
||||||
build\binaries\mainExecutable
|
build/binaries/mainExecutable
|
||||||
|
|
||||||
node
|
node
|
||||||
----
|
----
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ executables {
|
|||||||
if (toolChain in VisualCpp) {
|
if (toolChain in VisualCpp) {
|
||||||
cCompiler.args "/MD"
|
cCompiler.args "/MD"
|
||||||
linker.args "/SUBSYSTEM:CONSOLE", "/LIBPATH:../build/SDL2-2.0.3/lib/x86/", "SDL2main.lib", "SDL2.lib"
|
linker.args "/SUBSYSTEM:CONSOLE", "/LIBPATH:../build/SDL2-2.0.3/lib/x86/", "SDL2main.lib", "SDL2.lib"
|
||||||
//linker.args "/SUBSYSTEM:WINDOWS", "/LIBPATH:../build/SDL2-2.0.3/lib/x86/", "SDL2.lib"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
// 02-sdl2-video.cpp : SDL2 example - initialize video and display image
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <tchar.h>
|
|
||||||
#include "SDL.h"
|
|
||||||
|
|
||||||
int _tmain(int argc, _TCHAR* argv[]) {
|
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING) == -1){
|
|
||||||
printf("Error initializing SDL: %s\n", SDL_GetError());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Window *win = nullptr;
|
|
||||||
win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
|
|
||||||
if (win == nullptr){
|
|
||||||
printf("%i\n", SDL_GetError());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Renderer *ren = nullptr;
|
|
||||||
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
|
||||||
if (ren == nullptr){
|
|
||||||
printf("%i\n", SDL_GetError());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Surface *bmp = nullptr;
|
|
||||||
bmp = SDL_LoadBMP("smajlik.bmp");
|
|
||||||
if (bmp == nullptr){
|
|
||||||
printf("%i\n", SDL_GetError());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Texture *tex = nullptr;
|
|
||||||
tex = SDL_CreateTextureFromSurface(ren, bmp);
|
|
||||||
SDL_FreeSurface(bmp);
|
|
||||||
|
|
||||||
SDL_RenderClear(ren);
|
|
||||||
SDL_RenderCopy(ren, tex, NULL, NULL);
|
|
||||||
SDL_RenderPresent(ren);
|
|
||||||
|
|
||||||
SDL_Delay(2000);
|
|
||||||
|
|
||||||
SDL_DestroyTexture(tex);
|
|
||||||
SDL_DestroyRenderer(ren);
|
|
||||||
SDL_DestroyWindow(win);
|
|
||||||
|
|
||||||
SDL_Quit();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
28
sdl/02-sdl2-video/build.gradle
Normal file
28
sdl/02-sdl2-video/build.gradle
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
apply plugin: 'c'
|
||||||
|
apply plugin: 'visual-studio'
|
||||||
|
|
||||||
|
sources {
|
||||||
|
main {
|
||||||
|
c {
|
||||||
|
source {
|
||||||
|
// Include just source, avoid including *.swp and other helper files
|
||||||
|
include "**/*.c"
|
||||||
|
}
|
||||||
|
exportedHeaders {
|
||||||
|
srcDir "../build/SDL2-2.0.3/include"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
executables {
|
||||||
|
main {
|
||||||
|
binaries.all {
|
||||||
|
if (toolChain in VisualCpp) {
|
||||||
|
cCompiler.args "/MD"
|
||||||
|
linker.args "/SUBSYSTEM:CONSOLE", "/LIBPATH:../build/SDL2-2.0.3/lib/x86/", "SDL2main.lib", "SDL2.lib"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
52
sdl/02-sdl2-video/src/main/c/sdl2-video.c
Normal file
52
sdl/02-sdl2-video/src/main/c/sdl2-video.c
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
// 02-sdl2-video.cpp : SDL2 example - initialize video and display image
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "SDL.h"
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
SDL_Window *win = NULL;
|
||||||
|
SDL_Renderer *ren = NULL;
|
||||||
|
SDL_Surface *bmp = NULL;
|
||||||
|
SDL_Texture *tex = NULL;
|
||||||
|
|
||||||
|
if (SDL_Init(SDL_INIT_EVERYTHING) == -1){
|
||||||
|
printf("Error initializing SDL: %s\n", SDL_GetError());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
|
||||||
|
if (win == NULL){
|
||||||
|
printf("%s\n", SDL_GetError());
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
|
if (ren == NULL){
|
||||||
|
printf("%s\n", SDL_GetError());
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
bmp = SDL_LoadBMP("./smajlik.bmp");
|
||||||
|
if (bmp == NULL){
|
||||||
|
printf("%s\n", SDL_GetError());
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
tex = SDL_CreateTextureFromSurface(ren, bmp);
|
||||||
|
SDL_FreeSurface(bmp);
|
||||||
|
|
||||||
|
SDL_RenderClear(ren);
|
||||||
|
SDL_RenderCopy(ren, tex, NULL, NULL);
|
||||||
|
SDL_RenderPresent(ren);
|
||||||
|
|
||||||
|
SDL_Delay(2000);
|
||||||
|
|
||||||
|
SDL_DestroyTexture(tex);
|
||||||
|
SDL_DestroyRenderer(ren);
|
||||||
|
SDL_DestroyWindow(win);
|
||||||
|
|
||||||
|
SDL_Quit();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user