Merge pull request #1 from thinkingmaster/master

Add CMake support + rotation
This commit is contained in:
nullifiedcat 2018-04-28 20:19:52 +03:00 committed by GitHub
commit f771f59642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 139 additions and 85 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
bin*
*.o
.settings*
.settings*
build

View File

@ -4,7 +4,7 @@
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(g?cc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(g?cc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1065738691104269017" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>

48
CMakeLists.txt Normal file
View File

@ -0,0 +1,48 @@
# This builds a 32-bit version of library, building 64 bit is not supported yet.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type")
endif()
set(CMAKE_BUILD_TYPE_VALUES "Debug;Release" CACHE INTERNAL "List of supported build")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_BUILD_TYPE_VALUES})
cmake_minimum_required(VERSION 3.0)
project(glez LANGUAGES C VERSION 0.0.1)
set(export_dest "lib/${PROJECT_NAME}-${PROJECT_VERSION}")
set(include_dest "include/${PROJECT_NAME}-${PROJECT_VERSION}")
set(lib_dest "${export_dest}/${CMAKE_BUILD_TYPE}")
find_package(Freetype REQUIRED)
find_package(PNG REQUIRED)
find_package(GLEW REQUIRED)
add_library(${PROJECT_NAME} SHARED "")
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/ftgl>
$<BUILD_INTERFACE:${FREETYPE_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${PNG_INCLUDE_DIR}>
$<BUILD_INTERFACE:${GLEW_INCLUDE_DIRS}>
)
target_include_directories(${PROJECT_NAME} PUBLIC
$<INSTALL_INTERFACE:${include_dest}>
)
target_compile_definitions(${PROJECT_NAME} PRIVATE ${PNG_DEFINITIONS})
target_link_libraries(${PROJECT_NAME} ${FREETYPE_LIBRARIES} ${PNG_LIBRARIES} ${GLEW_LIBRARIES})
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(ftgl)
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} DESTINATION "${lib_dest}")
install(FILES "include/glez.h" DESTINATION "${include_dest}")
install(EXPORT ${PROJECT_NAME} DESTINATION "${lib_dest}")
install(FILES ${PROJECT_NAME}-config.cmake DESTINATION ${export_dest})

View File

@ -1,76 +0,0 @@
CC=$(shell sh -c "which gcc-7 || which gcc")
CFLAGS=-O3 -Wall -fPIC -fmessage-length=0 -D_GNU_SOURCE=1 -g3 -ggdb -Iinclude -isystemftgl -isystem/usr/local/include/freetype2 -isystem/usr/include/freetype2
LDFLAGS=-shared -Wl,--no-undefined
LDLIBS=-lm -lrt -lGL -lfreetype -lGLEW -lpng
SRC_DIR=src
BIN32_DIR=bin32
BIN64_DIR=bin64
SOURCES=$(shell find $(SRC_DIR) -name "*.c" -print)
SOURCES+=$(shell find "ftgl" -name "*.c" -print)
OBJECTS=$(SOURCES:.c=.o)
LIB32_PATH=/lib/i386-linux-gnu
LIB64_PATH=/lib/x86_64-linux-gnu
TARGET32=$(BIN32_DIR)/libglez.so
TARGET64=$(BIN64_DIR)/libglez.so
TARGET=undefined
.PHONY: clean clean_objects
ifeq ($(ARCH),32)
CFLAGS+=-m32
LDFLAGS+=-m32
TARGET=$(TARGET32)
endif
ifeq ($(ARCH),64)
TARGET=$(TARGET64)
endif
all:
mkdir -p $(BIN32_DIR)
mkdir -p $(BIN64_DIR)
ifndef ARCH
$(MAKE) clean_objects
$(MAKE) -e ARCH=32
$(MAKE) clean_objects
$(MAKE) -e ARCH=64
else
$(MAKE) clean_objects
$(MAKE) $(TARGET)
endif
install:
cp $(TARGET32) $(LIB32_PATH)
cp $(TARGET64) $(LIB64_PATH)
cp -R include/. /usr/local/include/glez
ftgl/distance-field.o : CFLAGS+=-w
ftgl/edtaa3func.o : CFLAGS+=-w
ftgl/font-manager.o : CFLAGS+=-w
ftgl/mat4.o : CFLAGS+=-w
ftgl/platform.o : CFLAGS+=-w
ftgl/shader.o : CFLAGS+=-w
ftgl/text-buffer.o : CFLAGS+=-w
ftgl/texture-atlas.o : CFLAGS+=-w
ftgl/utf8-utils.o : CFLAGS+=-w
ftgl/texture-font.o : CFLAGS+=-w
ftgl/vector.o : CFLAGS+=-w
ftgl/vertex-attribute.o : CFLAGS+=-w
ftgl/vertex-buffer.o : CFLAGS+=-w
ftgl/makefont.o : CFLAGS+=-w
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -o $@
clean_objects:
find . -type f -name '*.o' -delete
clean:
find . -type f -name '*.o' -delete
find . -type f -name '*.d' -delete
rm -f bin32/*.so
rm -f bin64/*.so

32
ftgl/CMakeLists.txt Normal file
View File

@ -0,0 +1,32 @@
target_sources(glez PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/distance-field.h"
"${CMAKE_CURRENT_LIST_DIR}/edtaa3func.h"
"${CMAKE_CURRENT_LIST_DIR}/font-manager.h"
"${CMAKE_CURRENT_LIST_DIR}/freetype-gl.h"
"${CMAKE_CURRENT_LIST_DIR}/markup.h"
"${CMAKE_CURRENT_LIST_DIR}/mat4.h"
"${CMAKE_CURRENT_LIST_DIR}/opengl.h"
"${CMAKE_CURRENT_LIST_DIR}/platform.h"
"${CMAKE_CURRENT_LIST_DIR}/text-buffer.h"
"${CMAKE_CURRENT_LIST_DIR}/texture-atlas.h"
"${CMAKE_CURRENT_LIST_DIR}/texture-font.h"
"${CMAKE_CURRENT_LIST_DIR}/utf8-utils.h"
"${CMAKE_CURRENT_LIST_DIR}/vec234.h"
"${CMAKE_CURRENT_LIST_DIR}/vector.h"
"${CMAKE_CURRENT_LIST_DIR}/vertex-attribute.h"
"${CMAKE_CURRENT_LIST_DIR}/vertex-buffer.h")
target_sources(glez PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/distance-field.c"
"${CMAKE_CURRENT_LIST_DIR}/edtaa3func.c"
"${CMAKE_CURRENT_LIST_DIR}/font-manager.c"
"${CMAKE_CURRENT_LIST_DIR}/makefont.c"
"${CMAKE_CURRENT_LIST_DIR}/mat4.c"
"${CMAKE_CURRENT_LIST_DIR}/platform.c"
"${CMAKE_CURRENT_LIST_DIR}/text-buffer.c"
"${CMAKE_CURRENT_LIST_DIR}/texture-atlas.c"
"${CMAKE_CURRENT_LIST_DIR}/texture-font.c"
"${CMAKE_CURRENT_LIST_DIR}/utf8-utils.c"
"${CMAKE_CURRENT_LIST_DIR}/vector.c"
"${CMAKE_CURRENT_LIST_DIR}/vertex-attribute.c"
"${CMAKE_CURRENT_LIST_DIR}/vertex-buffer.c")

2
glez-config.cmake Normal file
View File

@ -0,0 +1,2 @@
get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
include(${SELF_DIR}/${CMAKE_BUILD_TYPE}/glez.cmake)

4
include/CMakeLists.txt Normal file
View File

@ -0,0 +1,4 @@
target_sources(glez PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/glez.h")
add_subdirectory(internal)

View File

@ -98,7 +98,7 @@ void glez_rect_outline(float x, float y, float w, float h, glez_rgba_t color,
void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color,
glez_texture_t texture, float tx, float ty, float tw,
float th);
float th, float angle);
void glez_string(float x, float y, const char *string, glez_font_t font,
glez_rgba_t color, float *out_x, float *out_y);

View File

@ -0,0 +1,5 @@
target_sources(glez PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/draw.h"
"${CMAKE_CURRENT_LIST_DIR}/fonts.h"
"${CMAKE_CURRENT_LIST_DIR}/program.h"
"${CMAKE_CURRENT_LIST_DIR}/textures.h")

6
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,6 @@
target_sources(glez PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/draw.c"
"${CMAKE_CURRENT_LIST_DIR}/fonts.c"
"${CMAKE_CURRENT_LIST_DIR}/glez.c"
"${CMAKE_CURRENT_LIST_DIR}/program.c"
"${CMAKE_CURRENT_LIST_DIR}/textures.c")

View File

@ -11,8 +11,10 @@
#include "internal/draw.h"
#include "internal/fonts.h"
#include "internal/textures.h"
#include <vec234.h>
#include <math.h>
#include <string.h>
/* State functions */
@ -135,10 +137,9 @@ void glez_rect_outline(float x, float y, float w, float h, glez_rgba_t color,
glez_line(x + w, y + h, -w, 0, color, thickness);
glez_line(x, y + h, 0, -h, color, thickness);
}
void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color,
glez_texture_t texture, float tx, float ty, float tw,
float th)
float th, float angle)
{
internal_texture_t *tex = internal_texture_get(texture);
internal_texture_bind(texture);
@ -184,6 +185,36 @@ void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color,
vertices[3].color = color;
vertices[3].mode = DRAW_MODE_TEXTURED;
if (angle) {
float v1[2] = {vertices[0].position.x, vertices[0].position.y};
float v2[2] = {vertices[1].position.x, vertices[1].position.y};
float v3[2] = {vertices[2].position.x, vertices[2].position.y};
float v4[2] = {vertices[3].position.x, vertices[3].position.y};
vertices[0].position.x = -tw;
vertices[1].position.x = -tw;
vertices[2].position.x = tw;
vertices[3].position.x = tw;
vertices[0].position.y = -th;
vertices[1].position.y = th;
vertices[2].position.y = th;
vertices[3].position.y = -th;
for (int i = 0; i < 4; i++) {
float x = vertices[i].position.x;
float y = vertices[i].position.y;
vertices[i].position.x = x *cos(angle) - y *sin(angle);
vertices[i].position.y = x *sin(angle) + y *cos(angle);
}
vertices[0].position.x += v1[0];
vertices[0].position.y += v1[1];
vertices[1].position.x += v2[0];
vertices[1].position.y += v2[1];
vertices[2].position.x += v3[0];
vertices[2].position.y += v3[1];
vertices[3].position.x += v4[0];
vertices[3].position.y += v4[1];
}
vertex_buffer_push_back(program.buffer, vertices, 4, indices, 6);
}

View File

@ -52,13 +52,14 @@ int internal_texture_load_png_rgba(const char *name, internal_texture_t *out)
png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (pngstr == NULL)
{
fclose(file);
return -1;
}
png_infop pnginfo = png_create_info_struct(pngstr);
png_infop pngend = png_create_info_struct(pngstr);
if (setjmp(png_jmpbuf(pngstr)))
{
png_destroy_read_struct(pngstr, pnginfo, pngend);
png_destroy_read_struct(&pngstr, &pnginfo, &pngend);
return -1;
}
png_init_io(pngstr, file);
@ -71,7 +72,7 @@ int internal_texture_load_png_rgba(const char *name, internal_texture_t *out)
int row_bytes;
if (PNG_COLOR_TYPE_RGBA != png_get_color_type(pngstr, pnginfo))
{
png_destroy_read_struct(pngstr, pnginfo, pngend);
png_destroy_read_struct(&pngstr, &pnginfo, &pngend);
fclose(file);
return -1;
}
@ -81,14 +82,14 @@ int internal_texture_load_png_rgba(const char *name, internal_texture_t *out)
out->data = malloc(row_bytes * height * sizeof(png_byte));
if (out->data == NULL)
{
png_destroy_read_struct(pngstr, pnginfo, pngend);
png_destroy_read_struct(&pngstr, &pnginfo, &pngend);
fclose(file);
return -1;
}
row_pointers = malloc(height * sizeof(png_bytep));
if (row_pointers == NULL)
{
png_destroy_read_struct(pngstr, pnginfo, pngend);
png_destroy_read_struct(&pngstr, &pnginfo, &pngend);
free(out->data);
fclose(file);
return -1;