update SDL2 video example with Gradle build

This commit is contained in:
Juraj Michalek
2014-04-19 18:57:14 +02:00
parent ceadb4719a
commit 04ec418c40
5 changed files with 81 additions and 54 deletions

View File

@@ -178,7 +178,7 @@ It is possible to generate project for Visual Studio:
Compiled binary will be stored in:
build\binaries\mainExecutable
build/binaries/mainExecutable
node
----

View File

@@ -21,7 +21,6 @@ executables {
if (toolChain in VisualCpp) {
cCompiler.args "/MD"
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"
}
}
}

View File

@@ -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;
}

View 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"
}
}
}
}

View 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;
}