original green
This commit is contained in:
parent
db6b36cfb7
commit
1954d63ecd
|
@ -7,3 +7,6 @@ sdl2-gfx/
|
|||
screen.png
|
||||
frames*/
|
||||
local/
|
||||
demo-linux
|
||||
glew/
|
||||
build/
|
||||
|
|
48
Makefile
48
Makefile
|
@ -1,24 +1,48 @@
|
|||
SDLCONFIG = /home/frank/local/sdl/bin/sdl2-config
|
||||
CFLAGS = $(shell $(SDLCONFIG) --cflags) -Wall -O2
|
||||
INC = -I$(PROJECTHOME)/glm -I$(PROJECTHOME)/sdl2-gfx -I$(PROJECTHOME)/glew
|
||||
CFLAGS = $(shell $(SDLCONFIG) --cflags) -Wall -O2 -c $(INC)
|
||||
LFLAGS = $(shell $(SDLCONFIG) --libs)
|
||||
export ANDROID_HOME = /home/frank/ext/software/android-sdk
|
||||
export ANDROID_NDK_HOME = /home/frank/ext/software/android-ndk-r8d
|
||||
BUILDDIR = build
|
||||
ANDROIDPROJECT = com.tarecontrol.demo
|
||||
SDLHOME = /home/frank/ext/software/SDL2-2.0.8
|
||||
PROJECTHOME = /home/frank/projects/public/games/pp/sdl
|
||||
SOFTWARE_ROOT = /home/frank/ext/software
|
||||
SDLHOME = $(SOFTWARE_ROOT)/SDL2-2.0.9
|
||||
SDL_IMG_HOME = $(SOFTWARE_ROOT)/SDL2_image-2.0.4
|
||||
SDL_TTF_HOME = $(SOFTWARE_ROOT)/SDL2_ttf-2.0.14
|
||||
GLEW_WIN32_HOME = $(SOFTWARE_ROOT)/glew-2.1.0-win32
|
||||
PROJECTHOME = /home/frank/projects/public/games/sdl-test
|
||||
EMSCRIPTENHOME = /home/frank/ext/software/emsdk/emscripten/tag-1.38.12
|
||||
SDLEMLIBSHOME = $(SDLHOME)/build/em/build/.libs
|
||||
EMBUILDDIR = em
|
||||
WINBUILDDIR = win
|
||||
SDLMINGWHOME = $(SDLHOME)/i686-w64-mingw32
|
||||
SDL_IMG_MINGW_HOME = $(SDL_IMG_HOME)/i686-w64-mingw32
|
||||
SDL_TTF_MINGW_HOME = $(SDL_TTF_HOME)/i686-w64-mingw32
|
||||
APPDIR = Main.app/Contents
|
||||
SYSFWPATH = /Library/Frameworks
|
||||
INC = -Iglm -Isdl2-gfx
|
||||
CC_LINUX = clang-7
|
||||
CPPC_LINUX = clang++-7
|
||||
|
||||
SDL2_gfxPrimitives.o : sdl2-gfx/SDL2_gfxPrimitives.c
|
||||
$(CC_LINUX) $(CFLAGS) $^
|
||||
|
||||
SDL2_rotozoom.o : sdl2-gfx/SDL2_rotozoom.c
|
||||
$(CC_LINUX) $(CFLAGS) $^
|
||||
|
||||
glew.o : glew/glew.c
|
||||
$(CC_LINUX) $(CFLAGS) $^
|
||||
|
||||
main.o : main.cpp
|
||||
$(CPPC_LINUX) $(CFLAGS) --std=c++17 $^
|
||||
|
||||
demo-linux : main.o glew.o SDL2_rotozoom.o SDL2_gfxPrimitives.o
|
||||
$(CPPC_LINUX) $(LFLAGS) -D__LINUX__ $^ -lGL -lSDL2_image -lSDL2_ttf -lstdc++fs -o main
|
||||
|
||||
linux :
|
||||
clang++-7 -std=c++17 -c $(CFLAGS) $(INC) -D__LINUX__ main.cpp sdl2-gfx/SDL2_gfxPrimitives.c sdl2-gfx/SDL2_rotozoom.c
|
||||
clang++-7 $(LFLAGS) SDL2_gfxPrimitives.o SDL2_rotozoom.o main.o -lSDL2_image -lSDL2_ttf -lGL -lstdc++fs -o main
|
||||
clang++-7 -std=c++17 -c $(CFLAGS) $(INC) -D__LINUX__ main.cpp \
|
||||
sdl2-gfx/SDL2_gfxPrimitives.c sdl2-gfx/SDL2_rotozoom.c glew/glew.c
|
||||
clang++-7 $(LFLAGS) SDL2_gfxPrimitives.o SDL2_rotozoom.o glew.o main.o -lGL -lSDL2_image -lSDL2_ttf -lstdc++fs -o main
|
||||
|
||||
android :
|
||||
if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi;
|
||||
|
@ -38,9 +62,15 @@ emscripten :
|
|||
mingw :
|
||||
if [ ! -d $(BUILDDIR)/$(WINBUILDDIR) ]; then mkdir -p $(BUILDDIR)/$(WINBUILDDIR); fi;
|
||||
cd $(BUILDDIR)/$(WINBUILDDIR) && \
|
||||
i686-w64-mingw32-g++ $(PROJECTHOME)/main.cpp -I$(SDLMINGWHOME)/include/SDL2 -L$(SDLMINGWHOME)/lib \
|
||||
-Wl,-rpath,$(SDLMINGWHOME)/lib -lmingw32 -lSDL2main -lSDL2 -lopengl32 -Wall -O2 -o main.exe && \
|
||||
cp $(SDLMINGWHOME)/bin/SDL2.dll .
|
||||
i686-w64-mingw32-g++ -std=c++17 $(PROJECTHOME)/main.cpp -I$(SDLMINGWHOME)/include/SDL2 \
|
||||
-I$(SDL_IMG_MINGW_HOME)/include/SDL2 -I$(SDL_TTF_MINGW_HOME)/include/SDL2 $(INC) \
|
||||
$(PROJECTHOME)/sdl2-gfx/SDL2_gfxPrimitives.c $(PROJECTHOME)/sdl2-gfx/SDL2_rotozoom.c $(PROJECTHOME)/glew/glew.c \
|
||||
-L$(SDLMINGWHOME)/lib -L$(SDL_IMG_MINGW_HOME)/lib -L$(SDL_TTF_MINGW_HOME)/lib \
|
||||
-lmingw32 -lSDL2_image \
|
||||
-lSDL2_ttf -lstdc++fs \
|
||||
-lSDL2main -lSDL2 -lopengl32 -Wall -O2 -o main.exe && \
|
||||
cp $(SDLMINGWHOME)/bin/SDL2.dll $(SDL_IMG_MINGW_HOME)/bin/SDL2_image.dll \
|
||||
$(SDL_TTF_MINGW_HOME)/bin/SDL2_ttf.dll .
|
||||
|
||||
osx :
|
||||
g++ -I $(SYSFWPATH)/SDL2.framework/Headers $(INC) \
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
https://glm.g-truc.net/0.9.9/api/index.html
|
||||
http://www.ferzkopp.net/Software/SDL2_gfx/Docs/html/index.html
|
||||
http://ogldev.atspace.co.uk/
|
||||
https://www.khronos.org/registry/OpenGL-Refpages/gl4/
|
||||
https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview
|
||||
http://www.opengl-tutorial.org/
|
||||
http://www.songho.ca/opengl/index.html
|
||||
http://www.learnopengles.com/
|
||||
http://wiki.libsdl.org/
|
|
@ -6,14 +6,10 @@ in vec3 in_Color;
|
|||
|
||||
out vec2 UV;
|
||||
out vec4 ex_Color;
|
||||
out vec4 pos;
|
||||
|
||||
uniform float r;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = vec4(in_Position, 1);
|
||||
UV = vertexUV;
|
||||
ex_Color = vec4(r * in_Color[0], (1 - r) * in_Color[1], in_Color[2], 1);
|
||||
pos = vec4(0, 0, 0, 0);
|
||||
ex_Color = vec4(in_Color, 1);
|
||||
}
|
||||
|
|
84
main.cpp
84
main.cpp
|
@ -9,7 +9,14 @@
|
|||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
#include <experimental/filesystem>
|
||||
namespace fs = std::experimental::filesystem;
|
||||
#else
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
#endif
|
||||
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <SDL.h>
|
||||
|
@ -17,16 +24,20 @@
|
|||
#include <SDL_ttf.h>
|
||||
#include <SDL2_gfxPrimitives.h>
|
||||
|
||||
#if defined(__LINUX__) or defined(__MINGW32__)
|
||||
// #if defined(__LINUX__) or defined(__MINGW32__)
|
||||
// #define GL_GLEXT_PROTOTYPES
|
||||
// #include <GL/gl.h>
|
||||
// #elif defined(__ANDROID__)
|
||||
// #include <GLES/gl.h>
|
||||
// #elif defined(__EMSCRIPTEN__)
|
||||
// #include <GLES2/gl2.h>
|
||||
// #elif defined(__APPLE__)
|
||||
// #include <OpenGL/gl3.h>
|
||||
// #endif
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
#elif defined(__ANDROID__)
|
||||
#include <GLES/gl.h>
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
#include <GLES2/gl2.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <OpenGL/gl3.h>
|
||||
#endif
|
||||
#define GLEW_STATIC
|
||||
#include <glew.h>
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
@ -234,7 +245,7 @@ struct Sprite : Node
|
|||
{
|
||||
|
||||
std::vector<SDL_Texture*> frames;
|
||||
std::vector<std::filesystem::path> frame_paths;
|
||||
std::vector<fs::path> frame_paths;
|
||||
int frame_ii = 0;
|
||||
Location location;
|
||||
|
||||
|
@ -253,7 +264,7 @@ struct Sprite : Node
|
|||
|
||||
void load();
|
||||
|
||||
void load_file(std::filesystem::path);
|
||||
void load_file(fs::path);
|
||||
|
||||
void add_frame(SDL_Texture*);
|
||||
|
||||
|
@ -308,20 +319,26 @@ struct Game : Node
|
|||
|
||||
Game()
|
||||
{
|
||||
setenv("SDL_VIDEO_X11_LEGACY_FULLSCREEN", "0", true);
|
||||
std::cout << "GLEW " << glewGetString(GLEW_VERSION) << std::endl;
|
||||
putenv("SDL_VIDEO_X11_LEGACY_FULLSCREEN=0");
|
||||
SDL_version version;
|
||||
SDL_GetVersion(&version);
|
||||
printf("SDL %d.%d.%d\n", version.major, version.minor, version.patch);
|
||||
fprintf(stderr, "stderr test message\n");
|
||||
SDL_SetMainReady();
|
||||
// SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||
print_gl_attributes();
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
{
|
||||
print_sdl_error("SDL could not initialize");
|
||||
flag_to_end();
|
||||
}
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
// SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||
print_gl_attributes();
|
||||
window = SDL_CreateWindow("TARE control", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
sw, sh, SDL_WINDOW_OPENGL);
|
||||
if (window == NULL)
|
||||
|
@ -335,7 +352,7 @@ struct Game : Node
|
|||
print_sdl_error("Could not initialize SDL ttf");
|
||||
flag_to_end();
|
||||
}
|
||||
load_sdl_context();
|
||||
load_gl_context();
|
||||
}
|
||||
|
||||
void print_error(std::string message)
|
||||
|
@ -348,6 +365,14 @@ struct Game : Node
|
|||
std::cerr << message << " " << SDL_GetError() << std::endl;
|
||||
}
|
||||
|
||||
void print_gl_attributes()
|
||||
{
|
||||
int major, minor;
|
||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
|
||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
|
||||
std::cout << "GL CONTEXT: " << major << ", " << minor << std::endl;
|
||||
}
|
||||
|
||||
void load_sdl_context()
|
||||
{
|
||||
if (glcontext != NULL)
|
||||
|
@ -372,11 +397,22 @@ struct Game : Node
|
|||
}
|
||||
grass.unload();
|
||||
mushroom.unload();
|
||||
// SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||
print_gl_attributes();
|
||||
if ((glcontext = SDL_GL_CreateContext(window)) == NULL)
|
||||
{
|
||||
print_sdl_error("Could not get GL context");
|
||||
flag_to_end();
|
||||
}
|
||||
GLenum error = glewInit();
|
||||
if (error != GLEW_OK)
|
||||
{
|
||||
std::ostringstream message;
|
||||
message << "GLEW could not initialize " << glewGetErrorString(error);
|
||||
print_error(message.str());
|
||||
}
|
||||
printf("OpenGL %s, renderer %s, shading language %s\n", glGetString(GL_VERSION),
|
||||
glGetString(GL_RENDERER), glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
/*
|
||||
|
@ -779,17 +815,17 @@ Game* Node::get_root()
|
|||
|
||||
void Sprite::associate(std::string path)
|
||||
{
|
||||
if (std::filesystem::is_regular_file(path))
|
||||
if (fs::is_regular_file(path))
|
||||
{
|
||||
frame_paths.push_back(std::filesystem::path(path));
|
||||
frame_paths.push_back(fs::path(path));
|
||||
}
|
||||
else if (std::filesystem::is_directory(path))
|
||||
else if (fs::is_directory(path))
|
||||
{
|
||||
std::filesystem::directory_iterator directory(path);
|
||||
std::vector<std::filesystem::path> paths;
|
||||
std::copy(directory, std::filesystem::directory_iterator(), std::back_inserter(paths));
|
||||
fs::directory_iterator directory(path);
|
||||
std::vector<fs::path> paths;
|
||||
std::copy(directory, fs::directory_iterator(), std::back_inserter(paths));
|
||||
std::sort(paths.begin(), paths.end());
|
||||
for (const std::filesystem::path &name : paths)
|
||||
for (const fs::path &name : paths)
|
||||
{
|
||||
std::cout << "associating " << name << std::endl;
|
||||
frame_paths.push_back(name);
|
||||
|
@ -805,16 +841,16 @@ void Sprite::associate(std::string path)
|
|||
|
||||
void Sprite::load()
|
||||
{
|
||||
for (const std::filesystem::path &path : frame_paths)
|
||||
for (const fs::path &path : frame_paths)
|
||||
{
|
||||
load_file(path);
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::load_file(std::filesystem::path path)
|
||||
void Sprite::load_file(fs::path path)
|
||||
{
|
||||
Game *game = get_root();
|
||||
SDL_Texture *texture = IMG_LoadTexture(game->renderer, path.c_str());
|
||||
SDL_Texture *texture = IMG_LoadTexture(game->renderer, path.string().c_str());
|
||||
if (not texture)
|
||||
{
|
||||
game->print_sdl_error("Could not load image");
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
in vec4 ex_Color;
|
||||
in vec2 UV;
|
||||
in vec4 pos;
|
||||
uniform sampler2D myTextureSampler;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_FragColor = texture(myTextureSampler, UV) * ex_Color + pos;
|
||||
gl_FragColor = texture(myTextureSampler, UV) * ex_Color;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ in vec2 vertexUV;
|
|||
|
||||
out vec4 ex_Color;
|
||||
out vec2 UV;
|
||||
out vec4 pos;
|
||||
|
||||
uniform mat4 MVP;
|
||||
|
||||
|
@ -15,5 +14,4 @@ void main(void)
|
|||
gl_Position = MVP * vec4(in_Position, 1);
|
||||
ex_Color = vec4(in_Color, 1);
|
||||
UV = vertexUV;
|
||||
pos = vec4(vec3(MVP[0][0], MVP[0][1], MVP[0][2]) * vec3(UV, UV[0]), 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue