standalone application
This commit is contained in:
parent
7042cdb210
commit
f4844fd7fc
3
.gitignore
vendored
3
.gitignore
vendored
@ -21,4 +21,5 @@ minecraft/region*.lights.vtx
|
||||
minecraft/region*.dump
|
||||
minecraft/gen/map.txt
|
||||
test.pack
|
||||
pack_main
|
||||
pack_main
|
||||
.gdb_history
|
||||
11
Makefile
11
Makefile
@ -5,14 +5,13 @@ OBJCOPY=$(PREFIX)objcopy
|
||||
|
||||
OBJARCH = elf64-x86-64
|
||||
|
||||
OPT = -O2 -march=x86-64-v3
|
||||
OPT = -Og -march=x86-64-v3
|
||||
|
||||
#DEBUG = -g
|
||||
DEBUG = -g
|
||||
|
||||
CSTD = -std=gnu23
|
||||
CXXSTD = -std=gnu++23
|
||||
CFLAGS += -fpic
|
||||
CFLAGS += -I./include
|
||||
CFLAGS += -Wall -Werror -Wfatal-errors -Wno-error=unused-variable -Wno-error=unused-but-set-variable
|
||||
CFLAGS += -Wno-error=unknown-pragmas -Wno-unknown-pragmas
|
||||
CFLAGS += -Wno-error=unused-function
|
||||
@ -21,6 +20,8 @@ CFLAGS += -fno-strict-aliasing
|
||||
ifdef READ_PACK_FILE
|
||||
CFLAGS += -DREAD_PACK_FILE
|
||||
endif
|
||||
CFLAGS += -I./include
|
||||
CFLAGS += -I../SDL3-dist/include
|
||||
|
||||
LDFLAGS += -lm
|
||||
|
||||
@ -67,7 +68,7 @@ ifdef READ_PACK_FILE
|
||||
OBJS += test.pack.o
|
||||
endif
|
||||
|
||||
all: test.so
|
||||
all: main
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(ARCH) $(CSTD) $(CFLAGS) $(OPT) $(DEBUG) -c $< -o $@
|
||||
@ -88,7 +89,7 @@ test.so: $(OBJS)
|
||||
test.dll: $(OBJS)
|
||||
$(CXX) $(ARCH) $(OPT) -mthreads -static -mdll -static-libstdc++ -static-libgcc $(DEBUG) $^ -o $@ -L. -lSDL3 $(WINDOWS)
|
||||
|
||||
main: $(OBJS) src/main.o
|
||||
main: $(OBJS) src/main.o ../SDL3-dist/lib64/libSDL3.a
|
||||
$(CC) $(ARCH) $(LDFLAGS) $(OPT) $(DEBUG) $^ -o $@
|
||||
|
||||
clean:
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef _MSC_VER
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#define DECL __cdecl
|
||||
#else
|
||||
#define EXPORT __attribute__((dllexport))
|
||||
#define DECL __attribute__((__cdecl__))
|
||||
#endif
|
||||
#else
|
||||
#define EXPORT
|
||||
#define DECL
|
||||
#endif
|
||||
@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int draw_font_start();
|
||||
int draw_font(int font_ix, char const * text, int x, int y);
|
||||
|
||||
void draw_line_quad_start();
|
||||
void draw_line(int x1, int y1, int x2, int y2);
|
||||
void draw_set_color(float r, float g, float b);
|
||||
void draw_quad(int x1, int y1, int x2, int y2,
|
||||
int x3, int y3, int x4, int y4);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace pixel_line_art {
|
||||
|
||||
void load();
|
||||
|
||||
void draw_line_quad_start();
|
||||
void draw_line(int x1, int y1, int x2, int y2);
|
||||
void draw_set_color(float r, float g, float b);
|
||||
void draw_quad(int x1, int y1, int x2, int y2,
|
||||
int x3, int y3, int x4, int y4);
|
||||
}
|
||||
@ -1,28 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "declarations.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
EXPORT void DECL load(const char * source_path);
|
||||
EXPORT void DECL draw();
|
||||
EXPORT void DECL love2d_state_load();
|
||||
EXPORT void DECL love2d_state_restore();
|
||||
EXPORT void DECL update_keyboard(int up, int down, int left, int right,
|
||||
int w, int s, int a, int d,
|
||||
int t, int g, int f, int h,
|
||||
int i, int k, int j, int l,
|
||||
int q, int e);
|
||||
EXPORT void DECL update_mouse(int x, int y);
|
||||
EXPORT void DECL update_joystick(int joystick_index,
|
||||
float lx, float ly, float rx, float ry, float tl, float tr,
|
||||
int up, int down, int left, int right,
|
||||
int a, int b, int x, int y,
|
||||
int leftshoulder, int rightshoulder,
|
||||
int start);
|
||||
EXPORT void DECL update(float time);
|
||||
void load(const char * source_path);
|
||||
void draw();
|
||||
void love2d_state_load();
|
||||
void love2d_state_restore();
|
||||
void update_keyboard(int up, int down, int left, int right,
|
||||
int w, int s, int a, int d,
|
||||
int t, int g, int f, int h,
|
||||
int i, int k, int j, int l,
|
||||
int q, int e);
|
||||
void update_mouse(int x, int y);
|
||||
void update_joystick(int joystick_index,
|
||||
float lx, float ly, float rx, float ry, float tl, float tr,
|
||||
int up, int down, int left, int right,
|
||||
int a, int b, int x, int y,
|
||||
int leftshoulder, int rightshoulder,
|
||||
int start);
|
||||
void update(float time);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "declarations.h"
|
||||
|
||||
namespace window {
|
||||
extern float width;
|
||||
extern float height;
|
||||
@ -10,7 +8,7 @@ namespace window {
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
EXPORT void DECL update_window(int width, int height);
|
||||
void update_window(int width, int height);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
3
sdl3-build.sh
Normal file
3
sdl3-build.sh
Normal file
@ -0,0 +1,3 @@
|
||||
cmake ../SDL3-3.4.2/ -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../SDL3-dist
|
||||
cmake --build . --config Debug
|
||||
cmake --install . --config Debug
|
||||
@ -506,7 +506,6 @@ namespace collada::scene {
|
||||
glUniform1i(layout.uniform.specular_sampler, 3);
|
||||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_GREATER);
|
||||
glDisable(GL_CULL_FACE);
|
||||
//glCullFace(GL_FRONT);
|
||||
|
||||
@ -83,7 +83,6 @@ namespace flame {
|
||||
glUseProgram(program);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_GREATER);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
@ -244,7 +244,6 @@ namespace line_art {
|
||||
glUseProgram(program);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_ALWAYS);
|
||||
|
||||
glBindVertexArray(vertex_array_object);
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
#include "font/bitmap.h"
|
||||
#include "pixel_line_art.h"
|
||||
|
||||
#include "lua_api.h"
|
||||
|
||||
extern font::bitmap::font * terminus_fonts;
|
||||
extern unsigned int empty_vertex_array_object;
|
||||
extern unsigned int quad_index_buffer;
|
||||
|
||||
int draw_font_start()
|
||||
{
|
||||
int font_ix = font::bitmap::best_font(font::bitmap::terminus, font::bitmap::terminus_length);
|
||||
font::bitmap::font const& ter_best = terminus_fonts[font_ix];
|
||||
font::bitmap::draw_start(ter_best, empty_vertex_array_object, quad_index_buffer);
|
||||
return font_ix;
|
||||
}
|
||||
|
||||
int draw_font(int font_ix, char const * text, int x, int y)
|
||||
{
|
||||
font::bitmap::font const& ter_best = terminus_fonts[font_ix];
|
||||
font::bitmap::draw_string(ter_best, text, x, y);
|
||||
return ter_best.desc->glyph_height;
|
||||
}
|
||||
|
||||
void draw_line_quad_start()
|
||||
{
|
||||
pixel_line_art::draw_line_quad_start();
|
||||
}
|
||||
|
||||
void draw_line(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
pixel_line_art::draw_line(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
void draw_set_color(float r, float g, float b)
|
||||
{
|
||||
pixel_line_art::draw_set_color(r, g, b);
|
||||
}
|
||||
|
||||
void draw_quad(int x1, int y1, int x2, int y2,
|
||||
int x3, int y3, int x4, int y4)
|
||||
{
|
||||
pixel_line_art::draw_quad(x1, y1, x2, y2,
|
||||
x3, y3, x4, y4);
|
||||
}
|
||||
53
src/main.c
53
src/main.c
@ -1,53 +0,0 @@
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "glad/gl.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
extern void load();
|
||||
extern void draw();
|
||||
|
||||
int main()
|
||||
{
|
||||
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
//glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
|
||||
|
||||
GLFWwindow* window = glfwCreateWindow(1024, 1024, "LearnOpenGL", NULL, NULL);
|
||||
if (window == NULL) {
|
||||
const char* description;
|
||||
glfwGetError(&description);
|
||||
printf("Failed to create GLFW window: %s\n", description);
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
|
||||
glViewport(0, 0, 1024, 1024);
|
||||
|
||||
load();
|
||||
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
|
||||
draw();
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
80
src/main.cpp
Normal file
80
src/main.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "glad/gl.h"
|
||||
|
||||
#include "test.h"
|
||||
#include "window.h"
|
||||
#include "view.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
SDL_SetAppMetadata("Bibliotheca", "1.0", "st.idk.bibliotheca");
|
||||
|
||||
bool ret;
|
||||
ret = SDL_Init(SDL_INIT_VIDEO);
|
||||
if (!ret) {
|
||||
fprintf(stderr, "SDL_Init(SDL_INIT_VIDEO): %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
|
||||
SDL_WindowFlags window_flags
|
||||
= SDL_WINDOW_RESIZABLE
|
||||
| SDL_WINDOW_OPENGL
|
||||
;
|
||||
SDL_Window * window = SDL_CreateWindow("Bibliotheca", 1024, 1024, window_flags);
|
||||
if (window == NULL) {
|
||||
fprintf(stderr, "SDL_CreateWindow: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_GLContext context = SDL_GL_CreateContext(window);
|
||||
if (context == NULL) {
|
||||
fprintf(stderr, "SDL_GL_CreateContext: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
int version = gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress);
|
||||
if (version == 0) {
|
||||
fprintf(stderr, "gladLoadGL\n");
|
||||
}
|
||||
|
||||
load(".");
|
||||
|
||||
update_window(1024, 1024);
|
||||
|
||||
while (true) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_QUIT:
|
||||
goto exit;
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
if (event.key.key == SDLK_ESCAPE)
|
||||
goto exit;
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
printf("%d %d\n", event.window.data1, event.window.data2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
view::update_transforms();
|
||||
draw();
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
|
||||
exit:
|
||||
SDL_GL_DestroyContext(context);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -284,7 +284,6 @@ namespace minecraft {
|
||||
glUseProgram(program);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_GREATER);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
@ -109,7 +109,6 @@ namespace non_block {
|
||||
glUseProgram(program);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_GREATER);
|
||||
|
||||
XMVECTOR offset = view::state.at;
|
||||
|
||||
@ -1,138 +0,0 @@
|
||||
#include "glad/gl.h"
|
||||
#include "directxmath/directxmath.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "opengl.h"
|
||||
#include "window.h"
|
||||
|
||||
#include "pixel_line_art.h"
|
||||
|
||||
extern unsigned int quad_index_buffer;
|
||||
|
||||
namespace pixel_line_art {
|
||||
|
||||
struct layout {
|
||||
struct {
|
||||
unsigned int position;
|
||||
} attribute;
|
||||
struct {
|
||||
unsigned int transform;
|
||||
unsigned int base_color;
|
||||
} uniform;
|
||||
};
|
||||
|
||||
const layout layout = {
|
||||
.attribute = {
|
||||
.position = 0,
|
||||
},
|
||||
.uniform = {
|
||||
.transform = 0,
|
||||
.base_color = 1,
|
||||
},
|
||||
};
|
||||
|
||||
static unsigned int program;
|
||||
|
||||
static unsigned int vertex_array_object;
|
||||
static unsigned int per_vertex_buffer;
|
||||
static int const per_vertex_size = (sizeof (float)) * 2;
|
||||
|
||||
static void load_program()
|
||||
{
|
||||
program = compile_from_files("shader/pixel_line_art.vert",
|
||||
nullptr,
|
||||
"shader/pixel_line_art.frag");
|
||||
}
|
||||
|
||||
static void load_vertex_attributes()
|
||||
{
|
||||
glGenVertexArrays(1, &vertex_array_object);
|
||||
glBindVertexArray(vertex_array_object);
|
||||
|
||||
glVertexBindingDivisor(0, 0);
|
||||
|
||||
glEnableVertexAttribArray(layout.attribute.position);
|
||||
glVertexAttribFormat(layout.attribute.position, 2, GL_FLOAT, GL_FALSE, 0);
|
||||
glVertexAttribBinding(layout.attribute.position, 0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
static void load_per_vertex_buffer(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
float vertex_data[] = {
|
||||
(float)x1, (float)y1, (float)x2, (float)y2,
|
||||
};
|
||||
int vertex_data_size = (sizeof (vertex_data));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, per_vertex_buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertex_data_size, vertex_data, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
static void load_per_vertex_buffer2(int x1, int y1, int x2, int y2,
|
||||
int x3, int y3, int x4, int y4)
|
||||
{
|
||||
float vertex_data[] = {
|
||||
(float)x1, (float)y1, (float)x2, (float)y2,
|
||||
(float)x3, (float)y3, (float)x4, (float)y4,
|
||||
};
|
||||
int vertex_data_size = (sizeof (vertex_data));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, per_vertex_buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertex_data_size, vertex_data, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void load()
|
||||
{
|
||||
load_program();
|
||||
load_vertex_attributes();
|
||||
|
||||
glGenBuffers(1, &per_vertex_buffer);
|
||||
}
|
||||
|
||||
static void set_transform(XMMATRIX const & transform)
|
||||
{
|
||||
XMFLOAT4X4 float_transform;
|
||||
XMStoreFloat4x4(&float_transform, transform);
|
||||
glUniformMatrix4fv(layout.uniform.transform, 1, false, (float *)&float_transform);
|
||||
}
|
||||
|
||||
void draw_line_quad_start()
|
||||
{
|
||||
glUseProgram(program);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_ALWAYS);
|
||||
|
||||
glBindVertexArray(vertex_array_object);
|
||||
glBindVertexBuffer(0, per_vertex_buffer, 0, per_vertex_size);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_index_buffer);
|
||||
|
||||
XMMATRIX transform
|
||||
= XMMatrixScaling(2.0f / window::width, -2.0f / window::height, 0)
|
||||
* XMMatrixTranslation(-1, 1, 0);
|
||||
set_transform(transform);
|
||||
}
|
||||
|
||||
void draw_line(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
load_per_vertex_buffer(x1, y1, x2, y2);
|
||||
glDrawArrays(GL_LINES, 0, 2);
|
||||
}
|
||||
|
||||
void draw_quad(int x1, int y1, int x2, int y2,
|
||||
int x3, int y3, int x4, int y4)
|
||||
{
|
||||
load_per_vertex_buffer2(x1, y1, x2, y2,
|
||||
x3, y3, x4, y4);
|
||||
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, (void *)0);
|
||||
}
|
||||
|
||||
void draw_set_color(float r, float g, float b)
|
||||
{
|
||||
glUniform3f(layout.uniform.base_color, r, g, b);
|
||||
}
|
||||
}
|
||||
17
src/test.cpp
17
src/test.cpp
@ -2,6 +2,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "geometry_buffer.h"
|
||||
#include "glad/gl.h"
|
||||
#include "opengl.h"
|
||||
@ -29,7 +31,6 @@
|
||||
#include "flame.h"
|
||||
#include "new.h"
|
||||
#include "popcount.h"
|
||||
#include "declarations.h"
|
||||
|
||||
#include "world/entry_table.h"
|
||||
#include "world/world.h"
|
||||
@ -116,17 +117,12 @@ void load_quad_program()
|
||||
quad_program = program;
|
||||
}
|
||||
|
||||
extern "C" void * DECL SDL_GL_GetProcAddress(const char *proc);
|
||||
|
||||
void load(const char * source_path)
|
||||
{
|
||||
file::source_path_length = strlen(source_path);
|
||||
assert(source_path[file::source_path_length - 1] != '/');
|
||||
file::source_path = source_path;
|
||||
|
||||
fprintf(stderr, "getproc %p\n", SDL_GL_GetProcAddress);
|
||||
gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress);
|
||||
|
||||
//
|
||||
|
||||
glBindVertexArray(0);
|
||||
@ -213,6 +209,13 @@ void load(const char * source_path)
|
||||
|
||||
flame::load_program();
|
||||
flame::load_texture();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// opengl state
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
|
||||
void check_collisions(collision::Sphere const & sphere, XMVECTOR const & direction,
|
||||
@ -413,8 +416,6 @@ void update(float time)
|
||||
else
|
||||
view::state.at = XMVector3Transform(XMVectorZero(), node_at->world);
|
||||
*/
|
||||
|
||||
view::update_transforms();
|
||||
}
|
||||
|
||||
void draw_quad()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user