summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile13
-rw-r--r--config.c6
-rw-r--r--render_sdl.c18
-rw-r--r--util.c37
-rw-r--r--util.h2
5 files changed, 67 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index a0b995f..83f50f1 100644
--- a/Makefile
+++ b/Makefile
@@ -6,8 +6,12 @@ BLASTEM:=blastem.exe
RUNTIME32:=runtime_win.S
CC:=wine gcc.exe
-CFLAGS:=-O2 -std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -DDISABLE_OPENGL -I"C:/MinGW/usr/include/SDL"
-LDFLAGS:= -L"C:/MinGW/usr/lib" -lm -lmingw32 -lSDLmain -lSDL -mwindows
+CFLAGS:=-O2 -std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -I"C:/MinGW/usr/include/SDL" -DGLEW_STATIC
+LDFLAGS:= -L"C:/MinGW/usr/lib" -lm -lmingw32 -lSDLmain -lSDL
+ifndef NOGL
+LDFLAGS+= -lopengl32 -lglu32
+endif
+LDFLAGS+= -mwindows
CPU:=i686
else
@@ -76,6 +80,11 @@ else
MAINOBJS+= $(Z80OBJS)
endif
+ifdef WINDOWS
+ifndef NOGL
+MAINOBJS+= glew.o
+endif
+endif
all : dis zdis stateview vgmplay blastem
diff --git a/config.c b/config.c
index b9adf6f..eab0308 100644
--- a/config.c
+++ b/config.c
@@ -121,11 +121,8 @@ open_fail:
tern_node * load_config()
{
-#ifdef _WIN32
- tern_node * ret = parse_config_file("default.cfg");
-#else
char * exe_dir;
- char * home = getenv("HOME");
+ char * home = get_home_dir();
if (!home) {
goto load_in_app_dir;
}
@@ -143,7 +140,6 @@ load_in_app_dir:
path = alloc_concat(exe_dir, "/default.cfg");
ret = parse_config_file(path);
free(path);
-#endif
success:
if (ret) {
return ret;
diff --git a/render_sdl.c b/render_sdl.c
index e5f5c96..769af96 100644
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -113,14 +113,22 @@ const GLushort element_data[] = {0, 1, 2, 3};
GLuint load_shader(char * fname, GLenum shader_type)
{
- char * parts[] = {getenv("HOME"), "/.config/blastem/shaders/", fname};
+ char * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname};
char * shader_path = alloc_concat_m(3, parts);
+ printf("Trying to find shader at %s\n", shader_path);
FILE * f = fopen(shader_path, "r");
free(shader_path);
if (!f) {
+#ifdef _WIN32
+ parts[0] = "shaders/";
+ parts[1] = fname;
+ shader_path = alloc_concat_m(2, parts);
+#else
parts[0] = get_exe_dir();
parts[1] = "/shaders/";
shader_path = alloc_concat_m(3, parts);
+#endif
+ printf("Trying to find shader at %s\n", shader_path);
f = fopen(shader_path, "r");
free(shader_path);
if (!f) {
@@ -128,6 +136,7 @@ GLuint load_shader(char * fname, GLenum shader_type)
return 0;
}
}
+ puts("reading shader");
long fsize = file_size(f);
GLchar * text = malloc(fsize);
if (fread(text, 1, fsize, f) != fsize) {
@@ -138,6 +147,7 @@ GLuint load_shader(char * fname, GLenum shader_type)
GLuint ret = glCreateShader(shader_type);
glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize);
free(text);
+ puts("compiling shader");
glCompileShader(ret);
GLint compile_status, loglen;
glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status);
@@ -162,6 +172,7 @@ void render_alloc_surfaces(vdp_context * context)
context->oddbuf = context->framebuf = malloc(512 * 256 * 4 * 2);
memset(context->oddbuf, 0, 512 * 256 * 4 * 2);
context->evenbuf = ((char *)context->oddbuf) + 512 * 256 * 4;
+ puts("generating textures");
glGenTextures(3, textures);
for (int i = 0; i < 3; i++)
{
@@ -182,11 +193,15 @@ void render_alloc_surfaces(vdp_context * context)
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW);
+ puts("Loading vertex shader");
vshader = load_shader(tern_find_ptr_default(config, "videovertex_shader", "default.v.glsl"), GL_VERTEX_SHADER);
+ puts("loading fragment shader");
fshader = load_shader(tern_find_ptr_default(config, "videofragment_shader", "default.f.glsl"), GL_FRAGMENT_SHADER);
+ puts("creating program");
program = glCreateProgram();
glAttachShader(program, vshader);
glAttachShader(program, fshader);
+ puts("linking program");
glLinkProgram(program);
GLint link_status;
glGetProgramiv(program, GL_LINK_STATUS, &link_status);
@@ -205,6 +220,7 @@ void render_alloc_surfaces(vdp_context * context)
#ifndef DISABLE_OPENGL
}
#endif
+ puts("alloc surfaces done");
}
uint8_t render_depth()
diff --git a/util.c b/util.c
index 7fee9db..45eb9b8 100644
--- a/util.c
+++ b/util.c
@@ -75,7 +75,41 @@ void set_exe_str(char * str)
exe_str = str;
}
-#ifndef _WIN32
+#ifdef _WIN32
+#include "Shlobj.h"
+#include "Windows.h"
+
+char * get_home_dir()
+{
+ static char path[MAX_PATH];
+ SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path);
+ return path;
+}
+
+char * get_exe_dir()
+{
+ static char path[MAX_PATH];
+ HMODULE module = GetModuleHandleA(NULL);
+ GetModuleFileNameA(module, path, MAX_PATH);
+
+ int pathsize = strlen(path);
+ for(char * cur = path + pathsize - 1; cur != path; cur--)
+ {
+ if (*cur == '\\') {
+ *cur = 0;
+ break;
+ }
+ }
+ return path;
+}
+
+#else
+
+char * get_home_dir()
+{
+ return getenv("HOME");
+}
+
char * readlink_alloc(char * path)
{
char * linktext = NULL;
@@ -139,4 +173,5 @@ fallback:
}
return exe_dir;
}
+
#endif
diff --git a/util.h b/util.h
index d82ac50..780f538 100644
--- a/util.h
+++ b/util.h
@@ -19,6 +19,8 @@ char * split_keyval(char * text);
void set_exe_str(char * str);
//Returns the directory the executable is in
char * get_exe_dir();
+//Returns the user's home directory
+char * get_home_dir();
//Returns the contents of a symlink in a newly allocated string
char * readlink_alloc(char * path);