mirror of
https://github.com/nishiowo/nishbox
synced 2025-04-21 20:24:39 +00:00
rename stuff
This commit is contained in:
parent
f71f911431
commit
d031a07693
94
engine/gf_core.c
Normal file
94
engine/gf_core.c
Normal file
@ -0,0 +1,94 @@
|
||||
#define GF_EXPOSE_CORE
|
||||
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
#ifdef _WIN32
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
|
||||
/* Interface */
|
||||
#include <gf_core.h>
|
||||
|
||||
/* Engine */
|
||||
#include <gf_draw.h>
|
||||
#include <gf_physics.h>
|
||||
#include <gf_log.h>
|
||||
#include <gf_version.h>
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void gf_engine_begin(void) {
|
||||
gf_version_t ver;
|
||||
#ifdef _WIN32
|
||||
WSADATA wsa;
|
||||
#endif
|
||||
gf_get_version(&ver);
|
||||
gf_function_log("GoldFish Engine %s", ver.full);
|
||||
gf_function_log("Lua %s", ver.lua);
|
||||
gf_function_log("zlib %s", ver.zlib);
|
||||
gf_function_log("Thread model: %s", ver.thread);
|
||||
gf_function_log("OpenGL backend: %s", ver.opengl);
|
||||
#ifdef _WIN32
|
||||
WSAStartup(MAKEWORD(1, 1), &wsa);
|
||||
gf_function_log("Winsock ready", "");
|
||||
#endif
|
||||
gf_draw_begin();
|
||||
gf_physics_begin();
|
||||
}
|
||||
|
||||
void gf_engine_end(void) {
|
||||
gf_physics_end();
|
||||
gf_draw_end();
|
||||
}
|
||||
|
||||
gf_engine_t* gf_engine_create(int nogui) {
|
||||
gf_engine_t* engine = malloc(sizeof(*engine));
|
||||
memset(engine, 0, sizeof(*engine));
|
||||
if(nogui) {
|
||||
gf_function_log("No GUI mode", "");
|
||||
engine->draw = NULL;
|
||||
} else {
|
||||
gf_function_log("GUI mode", "");
|
||||
engine->draw = gf_draw_create();
|
||||
if(engine->draw == NULL) {
|
||||
gf_function_log("Failed to create drawing interface", "");
|
||||
free(engine);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
engine->physics = gf_physics_create();
|
||||
return engine;
|
||||
}
|
||||
|
||||
void gf_engine_set_draw(gf_engine_t* engine, void (*func)(gf_draw_t*)) { gf_draw_set_draw(engine->draw, func); }
|
||||
|
||||
/**
|
||||
* Writing this so I don't forget
|
||||
*
|
||||
* 1. Calls gf_draw_step
|
||||
* 2. gf_draw_step calls _gf_draw_step (Platform-dependent)
|
||||
* 3. _gf_draw_step processes platform-dependent stuffs (e.g. events)
|
||||
* 4. _gf_draw_step calls gf_draw_driver_before
|
||||
* 4. _gf_draw_step calls gf_draw_frame
|
||||
* 5. gf_draw_frame draws frame
|
||||
* 4. _gf_draw_step calls gf_draw_driver_after
|
||||
* 6. _gf_draw_step swaps buffers
|
||||
* 7. Comes back here
|
||||
*/
|
||||
void gf_engine_loop(gf_engine_t* engine) {
|
||||
while(1) {
|
||||
if(engine->draw != NULL) {
|
||||
if(gf_draw_step(engine->draw) != 0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gf_engine_destroy(gf_engine_t* engine) {
|
||||
if(engine->physics != NULL) gf_physics_destroy(engine->physics);
|
||||
if(engine->draw != NULL) gf_draw_destroy(engine->draw);
|
||||
free(engine);
|
||||
gf_function_log("Destroyed engine", "");
|
||||
}
|
80
engine/gf_draw_common.c
Normal file
80
engine/gf_draw_common.c
Normal file
@ -0,0 +1,80 @@
|
||||
#define GF_EXPOSE_DRAW
|
||||
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
|
||||
/* Interface */
|
||||
#include <gf_draw.h>
|
||||
|
||||
/* Engine */
|
||||
#include <gf_log.h>
|
||||
#include <gf_draw_platform.h>
|
||||
#include <gf_draw_driver.h>
|
||||
#include <gf_graphic.h>
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
void gf_draw_begin(void) { gf_draw_platform_begin(); }
|
||||
|
||||
void gf_draw_end(void) { gf_draw_platform_end(); }
|
||||
|
||||
gf_draw_t* gf_draw_create(void) {
|
||||
gf_draw_t* draw = malloc(sizeof(*draw));
|
||||
memset(draw, 0, sizeof(*draw));
|
||||
draw->x = 0;
|
||||
draw->y = 0;
|
||||
draw->width = 640;
|
||||
draw->height = 480;
|
||||
draw->running = 0;
|
||||
gf_draw_platform_create(draw);
|
||||
if(draw->platform != NULL) {
|
||||
gf_function_log("Created drawing interface successfully", "");
|
||||
gf_draw_driver_init(draw);
|
||||
gf_draw_reshape(draw);
|
||||
draw->running = 1;
|
||||
|
||||
draw->light[0] = 10.0;
|
||||
draw->light[1] = 10.0;
|
||||
draw->light[2] = 0.0;
|
||||
draw->light[3] = 1.0;
|
||||
|
||||
draw->camera[0] = 0;
|
||||
draw->camera[1] = 10;
|
||||
draw->camera[2] = 0;
|
||||
|
||||
draw->lookat[0] = 0;
|
||||
draw->lookat[1] = 0;
|
||||
draw->lookat[2] = 0;
|
||||
}
|
||||
return draw;
|
||||
}
|
||||
|
||||
void gf_draw_reshape(gf_draw_t* draw) { gf_draw_driver_reshape(draw); }
|
||||
|
||||
/* Runs every frame */
|
||||
void gf_draw_frame(gf_draw_t* draw) {
|
||||
if(draw->draw != NULL) draw->draw(draw);
|
||||
}
|
||||
|
||||
void gf_draw_set_draw(gf_draw_t* draw, void (*func)(gf_draw_t*)) { draw->draw = func; }
|
||||
|
||||
int gf_draw_step(gf_draw_t* draw) {
|
||||
int ret = gf_draw_platform_step(draw);
|
||||
if(ret != 0) return ret;
|
||||
draw->close = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void gf_draw_destroy(gf_draw_t* draw) {
|
||||
int i;
|
||||
if(draw->running) {
|
||||
gf_draw_driver_destroy(draw);
|
||||
}
|
||||
gf_draw_platform_destroy(draw);
|
||||
gf_function_log("Destroyed drawing interface", "");
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
#include <ne_pre.h>
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
|
||||
/* Interface */
|
||||
#include <ne_font.h>
|
||||
#include <gf_font.h>
|
||||
|
||||
/* NishBox */
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
unsigned char ne_font[128][8] = {
|
||||
unsigned char gf_font[128][8] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* U+0000 (nul) */
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* U+0001 */
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* U+0002 */
|
@ -1,17 +1,17 @@
|
||||
#include <ne_pre.h>
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
|
||||
/* Interface */
|
||||
#include <ne_log.h>
|
||||
#include <gf_log.h>
|
||||
|
||||
/* NishBox */
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
void ne_log(const char* fmt, ...) {
|
||||
void gf_log(const char* fmt, ...) {
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
vfprintf(stderr, fmt, va);
|
@ -1,42 +1,42 @@
|
||||
#include <ne_pre.h>
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <ode/odemath.h>
|
||||
|
||||
/* Interface */
|
||||
#include <ne_math.h>
|
||||
#include <gf_math.h>
|
||||
|
||||
/* NishBox */
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
float ne_log2(float x) { return log(x) / log(2); }
|
||||
float gf_log2(float x) { return log(x) / log(2); }
|
||||
|
||||
void ne_calculate_normal(ne_vector_t* r, ne_vector_t v0, ne_vector_t v1, ne_vector_t v2) {
|
||||
void gf_calculate_normal(gf_vector_t* r, gf_vector_t v0, gf_vector_t v1, gf_vector_t v2) {
|
||||
int i;
|
||||
dReal length;
|
||||
ne_vector_t vec;
|
||||
gf_vector_t vec;
|
||||
dReal res[3];
|
||||
dReal tmp0[3];
|
||||
dReal tmp1[3];
|
||||
dReal a[3]; /* v1 - v0 */
|
||||
dReal b[3]; /* v2 - v0 */
|
||||
|
||||
NE_VECTOR_COPY(tmp0, v1);
|
||||
NE_VECTOR_COPY(tmp1, v0);
|
||||
GF_VECTOR_COPY(tmp0, v1);
|
||||
GF_VECTOR_COPY(tmp1, v0);
|
||||
dSubtractVectors3(a, tmp0, tmp1); /* v1 - v0 */
|
||||
|
||||
NE_VECTOR_COPY(tmp0, v2);
|
||||
NE_VECTOR_COPY(tmp1, v0);
|
||||
GF_VECTOR_COPY(tmp0, v2);
|
||||
GF_VECTOR_COPY(tmp1, v0);
|
||||
dSubtractVectors3(b, tmp0, tmp1); /* v2 - v0 */
|
||||
|
||||
dCalcVectorCross3(res, a, b);
|
||||
|
||||
length = dCalcVectorLength3(res);
|
||||
NE_VECTOR_COPY(res, vec);
|
||||
GF_VECTOR_COPY(res, vec);
|
||||
|
||||
vec[0] /= length;
|
||||
vec[1] /= length;
|
13
engine/gf_mesh.c
Normal file
13
engine/gf_mesh.c
Normal file
@ -0,0 +1,13 @@
|
||||
#define GF_EXPOSE_MESH
|
||||
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
|
||||
/* Interface */
|
||||
#include <gf_mesh.h>
|
||||
|
||||
/* Engine */
|
||||
#include <gf_math.h>
|
||||
|
||||
/* Standard */
|
13
engine/gf_model.c
Normal file
13
engine/gf_model.c
Normal file
@ -0,0 +1,13 @@
|
||||
#define GF_EXPOSE_MODEL
|
||||
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
|
||||
/* Interface */
|
||||
#include <gf_model.h>
|
||||
|
||||
/* Engine */
|
||||
#include <gf_math.h>
|
||||
|
||||
/* Standard */
|
32
engine/gf_physics.c
Normal file
32
engine/gf_physics.c
Normal file
@ -0,0 +1,32 @@
|
||||
#define GF_EXPOSE_PHYSICS
|
||||
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <ode/ode.h>
|
||||
|
||||
/* Interface */
|
||||
#include <gf_physics.h>
|
||||
|
||||
/* Engine */
|
||||
#include <gf_log.h>
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
|
||||
void gf_physics_begin(void) { dInitODE(); }
|
||||
|
||||
void gf_physics_end(void) { dCloseODE(); }
|
||||
|
||||
gf_physics_t* gf_physics_create(void) {
|
||||
gf_physics_t* physics = malloc(sizeof(*physics));
|
||||
physics->id = dWorldCreate();
|
||||
dWorldSetGravity(physics->id, 0, 0, -9.81);
|
||||
return physics;
|
||||
}
|
||||
|
||||
void gf_physics_destroy(gf_physics_t* physics) {
|
||||
dWorldDestroy(physics->id);
|
||||
free(physics);
|
||||
gf_function_log("Destroyed physics", "");
|
||||
}
|
34
engine/gf_texture.c
Normal file
34
engine/gf_texture.c
Normal file
@ -0,0 +1,34 @@
|
||||
#define GF_EXPOSE_TEXTURE
|
||||
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
|
||||
/* Interface */
|
||||
#include <gf_texture.h>
|
||||
|
||||
/* Engine */
|
||||
#include <gf_draw_driver.h>
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
|
||||
gf_texture_t* gf_register_texture(gf_draw_t* draw, int width, int height, unsigned char* data) {
|
||||
gf_texture_t* texture = malloc(sizeof(*texture));
|
||||
gf_draw_driver_texture_t* ddtexture = gf_draw_driver_register_texture(draw, width, height, data);
|
||||
if(ddtexture == NULL) {
|
||||
free(texture);
|
||||
return NULL;
|
||||
}
|
||||
texture->width = width;
|
||||
texture->height = height;
|
||||
texture->draw_driver_texture = ddtexture;
|
||||
return texture;
|
||||
}
|
||||
|
||||
void gf_destroy_texture(gf_texture_t* texture) {
|
||||
gf_draw_driver_destroy_texture(texture->draw_driver_texture);
|
||||
free(texture);
|
||||
}
|
||||
|
||||
void gf_draw_texture(gf_draw_t* draw, float x, float y, float w, float h, gf_texture_t* texture, float r, float g, float b, float a) { gf_draw_driver_draw_texture(draw, x, y, w, h, texture->draw_driver_texture, r, g, b, a); }
|
@ -1,27 +1,27 @@
|
||||
#include <ne_pre.h>
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <lua.h>
|
||||
#include <zlib.h>
|
||||
|
||||
/* Interface */
|
||||
#include <ne_version.h>
|
||||
#include <gf_version.h>
|
||||
|
||||
/* NishBox */
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define NE_VERSION "1.0.0"
|
||||
#define GF_VERSION "1.0.0"
|
||||
|
||||
void ne_get_version(ne_version_t* version) {
|
||||
void gf_get_version(gf_version_t* version) {
|
||||
char* cpstr = malloc(512);
|
||||
int i;
|
||||
int incr = 0;
|
||||
int old = 0;
|
||||
|
||||
strcpy(version->full, NE_VERSION);
|
||||
strcpy(version->full, GF_VERSION);
|
||||
strcpy(version->zlib, ZLIB_VERSION);
|
||||
|
||||
strcpy(cpstr, LUA_RELEASE);
|
||||
@ -41,7 +41,7 @@ void ne_get_version(ne_version_t* version) {
|
||||
strcpy(version->thread, "POSIX");
|
||||
#endif
|
||||
|
||||
strcpy(cpstr, NE_VERSION);
|
||||
strcpy(cpstr, GF_VERSION);
|
||||
for(i = 0;; i++) {
|
||||
if(cpstr[i] == '.' || cpstr[i] == 0) {
|
||||
int num;
|
@ -1,23 +1,23 @@
|
||||
#define NE_EXPOSE_DRAW_DRIVER
|
||||
#define NE_EXPOSE_DRAW
|
||||
#define GF_EXPOSE_DRAW_DRIVER
|
||||
#define GF_EXPOSE_DRAW
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
/* Interface */
|
||||
#include <ne_draw_driver.h>
|
||||
#include <gf_draw_driver.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_draw_platform.h>
|
||||
#include <ne_texture.h>
|
||||
#include <ne_draw.h>
|
||||
#include <ne_log.h>
|
||||
#include <ne_font.h>
|
||||
#include <ne_math.h>
|
||||
#include <ne_graphic.h>
|
||||
/* Engine */
|
||||
#include <gf_draw_platform.h>
|
||||
#include <gf_texture.h>
|
||||
#include <gf_draw.h>
|
||||
#include <gf_log.h>
|
||||
#include <gf_font.h>
|
||||
#include <gf_math.h>
|
||||
#include <gf_graphic.h>
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
@ -28,10 +28,10 @@ GLfloat lightwht[] = {1.0, 1.0, 1.0, 1.0};
|
||||
GLfloat lightdim[] = {0.2, 0.2, 0.2, 1.0};
|
||||
GLfloat lightblk[] = {0.0, 0.0, 0.0, 1.0};
|
||||
|
||||
#define NEAREST_POW2(x) pow((2), ne_log2((int)(x) + 1))
|
||||
#define NEAREST_POW2(x) pow((2), gf_log2((int)(x) + 1))
|
||||
|
||||
ne_draw_driver_texture_t* ne_draw_driver_register_texture(ne_draw_t* draw, int width, int height, unsigned char* data) {
|
||||
ne_draw_driver_texture_t* r = malloc(sizeof(*r));
|
||||
gf_draw_driver_texture_t* gf_draw_driver_register_texture(gf_draw_t* draw, int width, int height, unsigned char* data) {
|
||||
gf_draw_driver_texture_t* r = malloc(sizeof(*r));
|
||||
int w = NEAREST_POW2(width);
|
||||
int h = NEAREST_POW2(height);
|
||||
int x, y;
|
||||
@ -58,12 +58,12 @@ ne_draw_driver_texture_t* ne_draw_driver_register_texture(ne_draw_t* draw, int w
|
||||
return r;
|
||||
}
|
||||
|
||||
void ne_draw_driver_destroy_texture(ne_draw_driver_texture_t* t) {
|
||||
void gf_draw_driver_destroy_texture(gf_draw_driver_texture_t* t) {
|
||||
glDeleteTextures(1, &t->id);
|
||||
free(t);
|
||||
}
|
||||
|
||||
void ne_draw_driver_init(ne_draw_t* draw) {
|
||||
void gf_draw_driver_init(gf_draw_t* draw) {
|
||||
int i;
|
||||
int w, h, ch;
|
||||
draw->driver = malloc(sizeof(*draw->driver));
|
||||
@ -90,28 +90,28 @@ void ne_draw_driver_init(ne_draw_t* draw) {
|
||||
|
||||
glLoadIdentity();
|
||||
|
||||
for(i = 0; i < sizeof(ne_font) / sizeof(ne_font[0]); i++) {
|
||||
for(i = 0; i < sizeof(gf_font) / sizeof(gf_font[0]); i++) {
|
||||
unsigned char* font = malloc(8 * 8 * 4);
|
||||
int j;
|
||||
for(j = 0; j < 8 * 8; j++) {
|
||||
unsigned char val = (ne_font[i][j / 8] >> (j % 8)) & 1 ? 255 : 0;
|
||||
unsigned char val = (gf_font[i][j / 8] >> (j % 8)) & 1 ? 255 : 0;
|
||||
font[j * 4 + 0] = val;
|
||||
font[j * 4 + 1] = val;
|
||||
font[j * 4 + 2] = val;
|
||||
font[j * 4 + 3] = val;
|
||||
}
|
||||
draw->font[i] = ne_register_texture(draw, 8, 8, font);
|
||||
draw->font[i] = gf_register_texture(draw, 8, 8, font);
|
||||
free(font);
|
||||
}
|
||||
ne_function_log("Registered %d glyphs", sizeof(ne_font) / sizeof(ne_font[0]));
|
||||
gf_function_log("Registered %d glyphs", sizeof(gf_font) / sizeof(gf_font[0]));
|
||||
|
||||
glClearColor(0, 0, 0, 1);
|
||||
|
||||
draw->driver->quadric = gluNewQuadric();
|
||||
}
|
||||
|
||||
int ne_draw_driver_has_extension(ne_draw_t* draw, const char* query) {
|
||||
int ret = ne_draw_platform_has_extension(draw, query);
|
||||
int gf_draw_driver_has_extension(gf_draw_t* draw, const char* query) {
|
||||
int ret = gf_draw_platform_has_extension(draw, query);
|
||||
const char* ext = NULL;
|
||||
const char* ptr;
|
||||
const int len = strlen(query);
|
||||
@ -122,7 +122,7 @@ int ne_draw_driver_has_extension(ne_draw_t* draw, const char* query) {
|
||||
return ((ptr != NULL) && ((ptr[len] == ' ') || (ptr[len] == '\0')));
|
||||
}
|
||||
|
||||
void ne_draw_driver_reshape(ne_draw_t* draw) {
|
||||
void gf_draw_driver_reshape(gf_draw_t* draw) {
|
||||
glViewport(0, 0, (GLint)draw->width, (GLint)draw->height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
@ -132,8 +132,8 @@ void ne_draw_driver_reshape(ne_draw_t* draw) {
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
void ne_draw_driver_draw_texture(ne_draw_t* draw, float x, float y, float w, float h, ne_draw_driver_texture_t* texture, float r, float g, float b, float a) {
|
||||
ne_graphic_begin_2d(draw);
|
||||
void gf_draw_driver_draw_texture(gf_draw_t* draw, float x, float y, float w, float h, gf_draw_driver_texture_t* texture, float r, float g, float b, float a) {
|
||||
gf_graphic_begin_2d(draw);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
@ -155,19 +155,19 @@ void ne_draw_driver_draw_texture(ne_draw_t* draw, float x, float y, float w, flo
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
ne_graphic_end_2d(draw);
|
||||
gf_graphic_end_2d(draw);
|
||||
}
|
||||
|
||||
void ne_draw_driver_destroy(ne_draw_t* draw) {
|
||||
void gf_draw_driver_destroy(gf_draw_t* draw) {
|
||||
int i;
|
||||
for(i = 0; i < sizeof(ne_font) / sizeof(ne_font[0]); i++) {
|
||||
ne_destroy_texture(draw->font[i]);
|
||||
for(i = 0; i < sizeof(gf_font) / sizeof(gf_font[0]); i++) {
|
||||
gf_destroy_texture(draw->font[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ne_draw_driver_before(ne_draw_t* draw) {
|
||||
void gf_draw_driver_before(gf_draw_t* draw) {
|
||||
GLfloat lightpos[3];
|
||||
NE_VECTOR_COPY(draw->light, lightpos);
|
||||
GF_VECTOR_COPY(draw->light, lightpos);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
@ -175,10 +175,10 @@ void ne_draw_driver_before(ne_draw_t* draw) {
|
||||
gluLookAt(draw->camera[0], draw->camera[1], draw->camera[2], draw->lookat[0], draw->lookat[1], draw->lookat[2], 0, 1, 0);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
|
||||
glPushMatrix();
|
||||
ne_graphic_clear(draw);
|
||||
gf_graphic_clear(draw);
|
||||
}
|
||||
|
||||
void ne_draw_driver_after(ne_draw_t* draw) {
|
||||
void gf_draw_driver_after(gf_draw_t* draw) {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
}
|
@ -1,21 +1,21 @@
|
||||
#define NE_EXPOSE_DRAW
|
||||
#define GF_EXPOSE_DRAW
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
/* Interface */
|
||||
#include <ne_graphic.h>
|
||||
#include <gf_graphic.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_draw.h>
|
||||
#include <ne_texture.h>
|
||||
/* Engine */
|
||||
#include <gf_draw.h>
|
||||
#include <gf_texture.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
void ne_graphic_begin_2d(ne_draw_t* draw) {
|
||||
void gf_graphic_begin_2d(gf_draw_t* draw) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
@ -25,7 +25,7 @@ void ne_graphic_begin_2d(ne_draw_t* draw) {
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
void ne_graphic_end_2d(ne_draw_t* draw) {
|
||||
void gf_graphic_end_2d(gf_draw_t* draw) {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
@ -33,11 +33,11 @@ void ne_graphic_end_2d(ne_draw_t* draw) {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
void ne_graphic_clear(ne_draw_t* draw) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
|
||||
void gf_graphic_clear(gf_draw_t* draw) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
|
||||
|
||||
void ne_graphic_text(ne_draw_t* draw, float x, float y, float size, const char* text, float r, float g, float b, float a) {
|
||||
void gf_graphic_text(gf_draw_t* draw, float x, float y, float size, const char* text, float r, float g, float b, float a) {
|
||||
int i;
|
||||
for(i = 0; text[i] != 0; i++) {
|
||||
ne_draw_texture(draw, x + i * (size / 2), y, size / 2, size, draw->font[text[i]], r, g, b, a);
|
||||
gf_draw_texture(draw, x + i * (size / 2), y, size / 2, size, draw->font[text[i]], r, g, b, a);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#define NE_EXPOSE_DRAW_PLATFORM
|
||||
#define NE_EXPOSE_DRAW
|
||||
#define GF_EXPOSE_DRAW_PLATFORM
|
||||
#define GF_EXPOSE_DRAW
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <GL/gl.h>
|
||||
@ -9,18 +9,18 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
/* Interface */
|
||||
#include <ne_draw_platform.h>
|
||||
#include <gf_draw_platform.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_draw_driver.h>
|
||||
#include <ne_log.h>
|
||||
#include <ne_draw.h>
|
||||
/* Engine */
|
||||
#include <gf_draw_driver.h>
|
||||
#include <gf_log.h>
|
||||
#include <gf_draw.h>
|
||||
|
||||
/* Standard */
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void ne_draw_platform_begin(void) {
|
||||
void gf_draw_platform_begin(void) {
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
|
||||
@ -28,17 +28,17 @@ void ne_draw_platform_begin(void) {
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
|
||||
}
|
||||
|
||||
void ne_draw_platform_end(void) {}
|
||||
void gf_draw_platform_end(void) {}
|
||||
|
||||
void ne_glfw_size(GLFWwindow* window, int w, int h) {
|
||||
ne_draw_t* draw = (ne_draw_t*)glfwGetWindowUserPointer(window);
|
||||
void gf_glfw_size(GLFWwindow* window, int w, int h) {
|
||||
gf_draw_t* draw = (gf_draw_t*)glfwGetWindowUserPointer(window);
|
||||
draw->width = w;
|
||||
draw->height = h;
|
||||
glfwSetWindowSize(window, w, h);
|
||||
ne_draw_reshape(draw);
|
||||
gf_draw_reshape(draw);
|
||||
}
|
||||
|
||||
int ne_draw_platform_has_extension(ne_draw_t* draw, const char* query) {
|
||||
int gf_draw_platform_has_extension(gf_draw_t* draw, const char* query) {
|
||||
const char* ext = NULL;
|
||||
const char* ptr;
|
||||
const int len = strlen(query);
|
||||
@ -48,7 +48,7 @@ int ne_draw_platform_has_extension(ne_draw_t* draw, const char* query) {
|
||||
return glfwExtensionSupported(query);
|
||||
}
|
||||
|
||||
int ne_draw_platform_step(ne_draw_t* draw) {
|
||||
int gf_draw_platform_step(gf_draw_t* draw) {
|
||||
int ret = 0;
|
||||
int w, h;
|
||||
glfwMakeContextCurrent(draw->platform->window);
|
||||
@ -56,28 +56,28 @@ int ne_draw_platform_step(ne_draw_t* draw) {
|
||||
if(draw->close) glfwSetWindowShouldClose(draw->platform->window, GLFW_FALSE);
|
||||
glfwPollEvents();
|
||||
if(ret == 0) {
|
||||
ne_draw_driver_before(draw);
|
||||
ne_draw_frame(draw);
|
||||
ne_draw_driver_after(draw);
|
||||
gf_draw_driver_before(draw);
|
||||
gf_draw_frame(draw);
|
||||
gf_draw_driver_after(draw);
|
||||
|
||||
glfwSwapBuffers(draw->platform->window);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
void gf_draw_platform_create(gf_draw_t* draw) {
|
||||
draw->platform = malloc(sizeof(*draw->platform));
|
||||
memset(draw->platform, 0, sizeof(*draw->platform));
|
||||
|
||||
draw->platform->window = glfwCreateWindow(draw->width, draw->height, "NishBox (GLFW)", NULL, NULL);
|
||||
if(draw->platform->window == NULL) {
|
||||
ne_function_log("Failed to create window", "");
|
||||
ne_draw_destroy(draw);
|
||||
gf_function_log("Failed to create window", "");
|
||||
gf_draw_destroy(draw);
|
||||
return;
|
||||
}
|
||||
|
||||
glfwSetWindowUserPointer(draw->platform->window, draw);
|
||||
glfwSetWindowSizeCallback(draw->platform->window, ne_glfw_size);
|
||||
glfwSetWindowSizeCallback(draw->platform->window, gf_glfw_size);
|
||||
|
||||
glfwMakeContextCurrent(draw->platform->window);
|
||||
#ifdef DO_SWAP_INTERVAL
|
||||
@ -85,7 +85,7 @@ void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void ne_draw_platform_destroy(ne_draw_t* draw) {
|
||||
void gf_draw_platform_destroy(gf_draw_t* draw) {
|
||||
if(draw->platform->window != NULL) {
|
||||
glfwDestroyWindow(draw->platform->window);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#define NE_EXPOSE_DRAW_PLATFORM
|
||||
#define NE_EXPOSE_DRAW
|
||||
#define GF_EXPOSE_DRAW_PLATFORM
|
||||
#define GF_EXPOSE_DRAW
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <GL/gl.h>
|
||||
@ -11,12 +11,12 @@
|
||||
#include <GL/glxext.h>
|
||||
|
||||
/* Interface */
|
||||
#include <ne_draw_platform.h>
|
||||
#include <gf_draw_platform.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_draw_driver.h>
|
||||
#include <ne_log.h>
|
||||
#include <ne_draw.h>
|
||||
/* Engine */
|
||||
#include <gf_draw_driver.h>
|
||||
#include <gf_log.h>
|
||||
#include <gf_draw.h>
|
||||
|
||||
/* Standard */
|
||||
#include <string.h>
|
||||
@ -38,10 +38,10 @@ typedef void (*PFNGLXSWAPINTERVALEXTPROC)(Display*, GLXDrawable, int);
|
||||
typedef void (*PFNGLXSWAPINTERVALSGIPROC)(int);
|
||||
#endif
|
||||
|
||||
void ne_draw_platform_begin(void) {}
|
||||
void ne_draw_platform_end(void) {}
|
||||
void gf_draw_platform_begin(void) {}
|
||||
void gf_draw_platform_end(void) {}
|
||||
|
||||
int ne_draw_platform_has_extension(ne_draw_t* draw, const char* query) {
|
||||
int gf_draw_platform_has_extension(gf_draw_t* draw, const char* query) {
|
||||
const char* ext = NULL;
|
||||
const char* ptr;
|
||||
const int len = strlen(query);
|
||||
@ -53,7 +53,7 @@ int ne_draw_platform_has_extension(ne_draw_t* draw, const char* query) {
|
||||
return ((ptr != NULL) && ((ptr[len] == ' ') || (ptr[len] == '\0')));
|
||||
}
|
||||
|
||||
void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
void gf_draw_platform_create(gf_draw_t* draw) {
|
||||
int i = 0;
|
||||
int attribs[64];
|
||||
int screen;
|
||||
@ -68,8 +68,8 @@ void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
|
||||
draw->platform->display = XOpenDisplay(NULL);
|
||||
if(draw->platform->display == NULL) {
|
||||
ne_function_log("Failed to open display", "");
|
||||
ne_draw_destroy(draw);
|
||||
gf_function_log("Failed to open display", "");
|
||||
gf_draw_destroy(draw);
|
||||
return;
|
||||
}
|
||||
attribs[i++] = GLX_RGBA;
|
||||
@ -91,8 +91,8 @@ void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
|
||||
visual = glXChooseVisual(draw->platform->display, screen, attribs);
|
||||
if(visual == NULL) {
|
||||
ne_function_log("Failed to get visual", "");
|
||||
ne_draw_destroy(draw);
|
||||
gf_function_log("Failed to get visual", "");
|
||||
gf_draw_destroy(draw);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -114,8 +114,8 @@ void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
draw->platform->context = glXCreateContext(draw->platform->display, visual, NULL, True);
|
||||
if(draw->platform->context == NULL) {
|
||||
XFree(visual);
|
||||
ne_function_log("Failed to get OpenGL context", "");
|
||||
ne_draw_destroy(draw);
|
||||
gf_function_log("Failed to get OpenGL context", "");
|
||||
gf_draw_destroy(draw);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
glXMakeCurrent(draw->platform->display, draw->platform->window, draw->platform->context);
|
||||
|
||||
#ifdef DO_SWAP_INTERVAL
|
||||
if(ne_draw_platform_has_extension(draw, "GLX_EXT_swap_control")) {
|
||||
if(gf_draw_platform_has_extension(draw, "GLX_EXT_swap_control")) {
|
||||
unsigned int tmp = -1;
|
||||
PFNGLXSWAPINTERVALEXTPROC proc = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB("glXSwapIntervalEXT");
|
||||
if(proc != NULL) {
|
||||
@ -133,25 +133,25 @@ void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
}
|
||||
glXQueryDrawable(draw->platform->display, draw->platform->window, GLX_SWAP_INTERVAL_EXT, &tmp);
|
||||
interval = tmp;
|
||||
} else if(ne_draw_platform_has_extension(draw, "GLX_MESA_swap_control")) {
|
||||
} else if(gf_draw_platform_has_extension(draw, "GLX_MESA_swap_control")) {
|
||||
PFNGLXGETSWAPINTERVALMESAPROC proc = (PFNGLXGETSWAPINTERVALMESAPROC)glXGetProcAddressARB("glXGetSwapIntervalMESA");
|
||||
PFNGLXSWAPINTERVALMESAPROC proc2 = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddressARB("glXSwapIntervalMESA");
|
||||
if(proc2 != NULL) {
|
||||
proc2(1);
|
||||
}
|
||||
interval = proc();
|
||||
} else if(ne_draw_platform_has_extension(draw, "GLX_SGI_swap_control")) {
|
||||
} else if(gf_draw_platform_has_extension(draw, "GLX_SGI_swap_control")) {
|
||||
PFNGLXSWAPINTERVALSGIPROC proc = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddressARB("glXSwapIntervalSGI");
|
||||
proc(1);
|
||||
interval = 1;
|
||||
}
|
||||
if(interval > 0) {
|
||||
ne_function_log("Enabled VSync", "");
|
||||
gf_function_log("Enabled VSync", "");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int ne_draw_platform_step(ne_draw_t* draw) {
|
||||
int gf_draw_platform_step(gf_draw_t* draw) {
|
||||
int ret = 0;
|
||||
glXMakeCurrent(draw->platform->display, draw->platform->window, draw->platform->context);
|
||||
while(XPending(draw->platform->display) > 0) {
|
||||
@ -165,7 +165,7 @@ int ne_draw_platform_step(ne_draw_t* draw) {
|
||||
draw->width = event.xconfigure.width;
|
||||
draw->height = event.xconfigure.height;
|
||||
glXMakeCurrent(draw->platform->display, draw->platform->window, draw->platform->context);
|
||||
ne_draw_reshape(draw);
|
||||
gf_draw_reshape(draw);
|
||||
} else if(event.type == ClientMessage) {
|
||||
if(event.xclient.data.l[0] == draw->platform->wm_delete_window) {
|
||||
draw->close = 1;
|
||||
@ -174,16 +174,16 @@ int ne_draw_platform_step(ne_draw_t* draw) {
|
||||
}
|
||||
}
|
||||
if(ret == 0) {
|
||||
ne_draw_driver_before(draw);
|
||||
ne_draw_frame(draw);
|
||||
ne_draw_driver_after(draw);
|
||||
gf_draw_driver_before(draw);
|
||||
gf_draw_frame(draw);
|
||||
gf_draw_driver_after(draw);
|
||||
|
||||
glXSwapBuffers(draw->platform->display, draw->platform->window);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ne_draw_platform_destroy(ne_draw_t* draw) {
|
||||
void gf_draw_platform_destroy(gf_draw_t* draw) {
|
||||
if(draw->platform->context != NULL) {
|
||||
glXMakeCurrent(draw->platform->display, None, NULL);
|
||||
glXDestroyContext(draw->platform->display, draw->platform->context);
|
@ -1,18 +1,18 @@
|
||||
#define NE_EXPOSE_DRAW_PLATFORM
|
||||
#define NE_EXPOSE_DRAW
|
||||
#define GF_EXPOSE_DRAW_PLATFORM
|
||||
#define GF_EXPOSE_DRAW
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <GL/gl.h>
|
||||
|
||||
/* Interface */
|
||||
#include <ne_draw_platform.h>
|
||||
#include <gf_draw_platform.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_draw_driver.h>
|
||||
#include <ne_log.h>
|
||||
#include <ne_draw.h>
|
||||
/* Engine */
|
||||
#include <gf_draw_driver.h>
|
||||
#include <gf_log.h>
|
||||
#include <gf_draw.h>
|
||||
|
||||
/* Standard */
|
||||
#include <string.h>
|
||||
@ -21,13 +21,13 @@
|
||||
typedef const char*(APIENTRY* PFNWGLGETEXTENSIONSSTRINGARB)(HDC);
|
||||
typedef BOOL(APIENTRY* PFNWGLSWAPINTERVALPROC)(int);
|
||||
|
||||
void ne_draw_platform_begin(void) {}
|
||||
void ne_draw_platform_end(void) {}
|
||||
void gf_draw_platform_begin(void) {}
|
||||
void gf_draw_platform_end(void) {}
|
||||
|
||||
LRESULT CALLBACK ne_draw_platform_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
|
||||
LRESULT CALLBACK gf_draw_platform_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {
|
||||
PAINTSTRUCT ps;
|
||||
RECT rect;
|
||||
ne_draw_t* draw = (ne_draw_t*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
||||
gf_draw_t* draw = (gf_draw_t*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
||||
switch(msg) {
|
||||
case WM_PAINT:
|
||||
BeginPaint(hWnd, &ps);
|
||||
@ -40,7 +40,7 @@ LRESULT CALLBACK ne_draw_platform_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp
|
||||
draw->width = rect.right - rect.left;
|
||||
draw->height = rect.bottom - rect.top;
|
||||
wglMakeCurrent(draw->platform->dc, draw->platform->glrc);
|
||||
ne_draw_reshape(draw);
|
||||
gf_draw_reshape(draw);
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
draw->close = 1;
|
||||
@ -54,7 +54,7 @@ LRESULT CALLBACK ne_draw_platform_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ne_draw_platform_has_extension(ne_draw_t* draw, const char* query) {
|
||||
int gf_draw_platform_has_extension(gf_draw_t* draw, const char* query) {
|
||||
const char* ext = NULL;
|
||||
const char* ptr;
|
||||
const int len = strlen(query);
|
||||
@ -72,7 +72,7 @@ int ne_draw_platform_has_extension(ne_draw_t* draw, const char* query) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ne_draw_platform_step(ne_draw_t* draw) {
|
||||
int gf_draw_platform_step(gf_draw_t* draw) {
|
||||
MSG msg;
|
||||
int ret = 0;
|
||||
wglMakeCurrent(draw->platform->dc, draw->platform->glrc);
|
||||
@ -86,16 +86,16 @@ int ne_draw_platform_step(ne_draw_t* draw) {
|
||||
}
|
||||
}
|
||||
if(ret == 0) {
|
||||
ne_draw_driver_before(draw);
|
||||
ne_draw_frame(draw);
|
||||
ne_draw_driver_after(draw);
|
||||
gf_draw_driver_before(draw);
|
||||
gf_draw_frame(draw);
|
||||
gf_draw_driver_after(draw);
|
||||
|
||||
SwapBuffers(draw->platform->dc);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
void gf_draw_platform_create(gf_draw_t* draw) {
|
||||
WNDCLASSEX wc;
|
||||
PIXELFORMATDESCRIPTOR desc;
|
||||
PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT;
|
||||
@ -108,16 +108,16 @@ void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
|
||||
draw->platform->instance = (HINSTANCE)GetModuleHandle(NULL);
|
||||
if(draw->platform->instance == NULL) {
|
||||
ne_function_log("Failed to get instance", "");
|
||||
ne_draw_destroy(draw);
|
||||
gf_function_log("Failed to get instance", "");
|
||||
gf_draw_destroy(draw);
|
||||
return;
|
||||
} else {
|
||||
ne_function_log("Got instance", "");
|
||||
gf_function_log("Got instance", "");
|
||||
}
|
||||
|
||||
wc.cbSize = sizeof(wc);
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
||||
wc.lpfnWndProc = ne_draw_platform_proc;
|
||||
wc.lpfnWndProc = gf_draw_platform_proc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = draw->platform->instance;
|
||||
@ -128,20 +128,20 @@ void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
wc.lpszClassName = "nishbox";
|
||||
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
|
||||
if(!RegisterClassEx(&wc)) {
|
||||
ne_function_log("Failed to register class", "");
|
||||
ne_draw_destroy(draw);
|
||||
gf_function_log("Failed to register class", "");
|
||||
gf_draw_destroy(draw);
|
||||
return;
|
||||
} else {
|
||||
ne_function_log("Registered class", "");
|
||||
gf_function_log("Registered class", "");
|
||||
}
|
||||
|
||||
draw->platform->window = CreateWindow("nishbox", "NishBox (WGL)", (WS_OVERLAPPEDWINDOW), draw->x, draw->y, draw->width, draw->height, NULL, 0, draw->platform->instance, NULL);
|
||||
if(draw->platform->window == NULL) {
|
||||
ne_function_log("Failed to create window", "");
|
||||
ne_draw_destroy(draw);
|
||||
gf_function_log("Failed to create window", "");
|
||||
gf_draw_destroy(draw);
|
||||
return;
|
||||
} else {
|
||||
ne_function_log("Created window", "");
|
||||
gf_function_log("Created window", "");
|
||||
}
|
||||
|
||||
SetWindowLongPtr(draw->platform->window, GWLP_USERDATA, (LONG_PTR)draw);
|
||||
@ -162,18 +162,18 @@ void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
|
||||
draw->platform->glrc = wglCreateContext(draw->platform->dc);
|
||||
if(draw->platform->glrc == NULL) {
|
||||
ne_function_log("Failed to create OpenGL context", "");
|
||||
ne_draw_destroy(draw);
|
||||
gf_function_log("Failed to create OpenGL context", "");
|
||||
gf_draw_destroy(draw);
|
||||
return;
|
||||
} else {
|
||||
ne_function_log("Created OpenGL context", "");
|
||||
gf_function_log("Created OpenGL context", "");
|
||||
}
|
||||
wglMakeCurrent(draw->platform->dc, draw->platform->glrc);
|
||||
|
||||
#ifdef DO_SWAP_INTERVAL
|
||||
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)wglGetProcAddress("wglSwapIntervalEXT");
|
||||
if(wglSwapIntervalEXT != NULL) {
|
||||
ne_function_log("Enabled VSync", "");
|
||||
gf_function_log("Enabled VSync", "");
|
||||
wglSwapIntervalEXT(1);
|
||||
}
|
||||
#endif
|
||||
@ -187,7 +187,7 @@ void ne_draw_platform_create(ne_draw_t* draw) {
|
||||
UpdateWindow(draw->platform->window);
|
||||
}
|
||||
|
||||
void ne_draw_platform_destroy(ne_draw_t* draw) {
|
||||
void gf_draw_platform_destroy(gf_draw_t* draw) {
|
||||
if(draw->platform->glrc != NULL) {
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
}
|
22
engine/include/gf_core.h
Normal file
22
engine/include/gf_core.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef __GF_CORE_H__
|
||||
#define __GF_CORE_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <gf_type/core.h>
|
||||
|
||||
/* Engine */
|
||||
#include <gf_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
void gf_engine_begin(void);
|
||||
void gf_engine_end(void);
|
||||
gf_engine_t* gf_engine_create(int nogui);
|
||||
void gf_engine_loop(gf_engine_t* engine);
|
||||
void gf_engine_set_draw(gf_engine_t* engine, void (*func)(gf_draw_t*));
|
||||
void gf_engine_destroy(gf_engine_t* engine);
|
||||
|
||||
#endif
|
23
engine/include/gf_draw.h
Normal file
23
engine/include/gf_draw.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef __GF_DRAW_H__
|
||||
#define __GF_DRAW_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <gf_type/draw.h>
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
gf_draw_t* gf_draw_create(void);
|
||||
void gf_draw_destroy(gf_draw_t* draw);
|
||||
void gf_draw_frame(gf_draw_t* draw);
|
||||
int gf_draw_step(gf_draw_t* draw);
|
||||
void gf_draw_begin(void);
|
||||
void gf_draw_end(void);
|
||||
void gf_draw_set_draw(gf_draw_t* engine, void (*func)(gf_draw_t*));
|
||||
void gf_draw_reshape(gf_draw_t* draw);
|
||||
|
||||
#endif
|
26
engine/include/gf_draw_driver.h
Normal file
26
engine/include/gf_draw_driver.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef __GF_DRAW_DRIVER_H__
|
||||
#define __GF_DRAW_DRIVER_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <gf_type/draw_driver.h>
|
||||
|
||||
/* Engine */
|
||||
#include <gf_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
void gf_draw_driver_init(gf_draw_t* draw);
|
||||
void gf_draw_driver_destroy(gf_draw_t* draw);
|
||||
int gf_draw_driver_has_extension(gf_draw_t* draw, const char* query);
|
||||
void gf_draw_driver_reshape(gf_draw_t* draw);
|
||||
|
||||
gf_draw_driver_texture_t* gf_draw_driver_register_texture(gf_draw_t* draw, int width, int height, unsigned char* data);
|
||||
void gf_draw_driver_destroy_texture(gf_draw_driver_texture_t* texture);
|
||||
void gf_draw_driver_draw_texture(gf_draw_t* draw, float x, float y, float w, float h, gf_draw_driver_texture_t* texture, float r, float g, float b, float a);
|
||||
void gf_draw_driver_before(gf_draw_t* draw);
|
||||
void gf_draw_driver_after(gf_draw_t* draw);
|
||||
|
||||
#endif
|
22
engine/include/gf_draw_platform.h
Normal file
22
engine/include/gf_draw_platform.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef __GF_DRAW_PLATFORM_H__
|
||||
#define __GF_DRAW_PLATFORM_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <gf_type/draw_platform.h>
|
||||
|
||||
/* Engine */
|
||||
#include <gf_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
void gf_draw_platform_create(gf_draw_t* draw);
|
||||
void gf_draw_platform_destroy(gf_draw_t* draw);
|
||||
int gf_draw_platform_step(gf_draw_t* draw);
|
||||
int gf_draw_platform_has_extension(gf_draw_t* draw, const char* query);
|
||||
void gf_draw_platform_begin(void);
|
||||
void gf_draw_platform_end(void);
|
||||
|
||||
#endif
|
15
engine/include/gf_font.h
Normal file
15
engine/include/gf_font.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef __GF_FONT_H__
|
||||
#define __GF_FONT_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
extern unsigned char gf_font[128][8];
|
||||
|
||||
#endif
|
19
engine/include/gf_graphic.h
Normal file
19
engine/include/gf_graphic.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef __GF_GRAPHIC_H__
|
||||
#define __GF_GRAPHIC_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
|
||||
/* Engine */
|
||||
#include <gf_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
void gf_graphic_clear(gf_draw_t* draw);
|
||||
void gf_graphic_begin_2d(gf_draw_t* draw);
|
||||
void gf_graphic_end_2d(gf_draw_t* draw);
|
||||
void gf_graphic_text(gf_draw_t* draw, float x, float y, float size, const char* text, float r, float g, float b, float a);
|
||||
|
||||
#endif
|
17
engine/include/gf_log.h
Normal file
17
engine/include/gf_log.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef __GF_LOG_H__
|
||||
#define __GF_LOG_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
#define gf_function_log(fmt, arg, ...) gf_log("%6d %24s: " fmt "\n", __LINE__, __FUNCTION_NAME__, arg)
|
||||
|
||||
void gf_log(const char* fmt, ...);
|
||||
|
||||
#endif
|
67
engine/include/gf_macro.h
Normal file
67
engine/include/gf_macro.h
Normal file
@ -0,0 +1,67 @@
|
||||
#ifndef __GF_MACRO_H__
|
||||
#define __GF_MACRO_H__
|
||||
|
||||
#ifdef GF_EXPOSE_ALL
|
||||
|
||||
#ifndef GF_EXPOSE_CORE
|
||||
#define GF_EXPOSE_CORE
|
||||
#endif
|
||||
|
||||
#ifndef GF_EXPOSE_DRAW
|
||||
#define GF_EXPOSE_DRAW
|
||||
#endif
|
||||
|
||||
#ifndef GF_EXPOSE_DRAW_PLATFORM
|
||||
#define GF_EXPOSE_DRAW_PLATFORM
|
||||
#endif
|
||||
|
||||
#ifndef GF_EXPOSE_MESH
|
||||
#define GF_EXPOSE_MESH
|
||||
#endif
|
||||
|
||||
#ifndef GF_EXPOSE_MODEL
|
||||
#define GF_EXPOSE_MODEL
|
||||
#endif
|
||||
|
||||
#ifndef GF_EXPOSE_TEXTURE
|
||||
#define GF_EXPOSE_TEXTURE
|
||||
#endif
|
||||
|
||||
#ifndef GF_EXPOSE_PHYSICS
|
||||
#define GF_EXPOSE_PHYSICS
|
||||
#endif
|
||||
|
||||
#ifndef GF_EXPOSE_MATH
|
||||
#define GF_EXPOSE_MATH
|
||||
#endif
|
||||
|
||||
#ifndef GF_EXPOSE_VERSION
|
||||
#define GF_EXPOSE_VERSION
|
||||
#endif
|
||||
|
||||
#ifndef GF_EXPOSE_DRAW_DRIVER
|
||||
#define GF_EXPOSE_DRAW_DRIVER
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef __FUNCTION_NAME__
|
||||
#ifdef _MSC_VER
|
||||
#define __FUNCTION_NAME__ __FUNCTION__
|
||||
#else
|
||||
#define __FUNCTION_NAME__ __func__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define GF_DECLARE_TYPE(n, b) typedef struct _gf_##n b gf_##n##_t;
|
||||
|
||||
/* Expose them by default */
|
||||
#ifndef GF_EXPOSE_MATH
|
||||
#define GF_EXPOSE_MATH
|
||||
#endif
|
||||
|
||||
#ifndef GF_EXPOSE_VERSION
|
||||
#define GF_EXPOSE_VERSION
|
||||
#endif
|
||||
|
||||
#endif
|
22
engine/include/gf_math.h
Normal file
22
engine/include/gf_math.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef __GF_MATH_H__
|
||||
#define __GF_MATH_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <gf_type/math.h>
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
#define GF_VECTOR_COPY(from, to) \
|
||||
to[0] = from[0]; \
|
||||
to[1] = from[1]; \
|
||||
to[2] = from[2]
|
||||
|
||||
float gf_log2(float x);
|
||||
void gf_calculate_normal(gf_vector_t* r, gf_vector_t v0, gf_vector_t v1, gf_vector_t v2);
|
||||
|
||||
#endif
|
14
engine/include/gf_mesh.h
Normal file
14
engine/include/gf_mesh.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef __GF_MESH_H__
|
||||
#define __GF_MESH_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <gf_type/mesh.h>
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
#endif
|
14
engine/include/gf_model.h
Normal file
14
engine/include/gf_model.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef __GF_MODEL_H__
|
||||
#define __GF_MODEL_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <gf_type/model.h>
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
#endif
|
19
engine/include/gf_physics.h
Normal file
19
engine/include/gf_physics.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef __GF_PHYSICS_H__
|
||||
#define __GF_PHYSICS_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <gf_type/physics.h>
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
void gf_physics_begin(void);
|
||||
void gf_physics_end(void);
|
||||
gf_physics_t* gf_physics_create(void);
|
||||
void gf_physics_destroy(gf_physics_t* physics);
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
#ifndef __NE_PRE_H__
|
||||
#define __NE_PRE_H__
|
||||
#ifndef __GF_PRE_H__
|
||||
#define __GF_PRE_H__
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
19
engine/include/gf_texture.h
Normal file
19
engine/include/gf_texture.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef __GF_TEXTURE_H__
|
||||
#define __GF_TEXTURE_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <gf_type/texture.h>
|
||||
|
||||
/* Engine */
|
||||
#include <gf_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
gf_texture_t* gf_register_texture(gf_draw_t* draw, int width, int height, unsigned char* data);
|
||||
void gf_destroy_texture(gf_texture_t* texture);
|
||||
void gf_draw_texture(gf_draw_t* draw, float x, float y, float w, float h, gf_texture_t* texture, float r, float g, float b, float a);
|
||||
|
||||
#endif
|
18
engine/include/gf_thread.h
Normal file
18
engine/include/gf_thread.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef __GF_THREAD_H__
|
||||
#define __GF_THREAD_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <gf_type/thread.h>
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
gf_thread_t* gf_create_thread(void (*func)(void*), void* userdata);
|
||||
void gf_join_thread(gf_thread_t* thread);
|
||||
void gf_destroy_thread(gf_thread_t* thread);
|
||||
|
||||
#endif
|
24
engine/include/gf_type/core.h
Normal file
24
engine/include/gf_type/core.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef __GF_TYPE_CORE_H__
|
||||
#define __GF_TYPE_CORE_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
#ifdef GF_EXPOSE_CORE
|
||||
/* External library */
|
||||
|
||||
/* Engine */
|
||||
#include <gf_type/physics.h>
|
||||
#include <gf_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
GF_DECLARE_TYPE(engine, {
|
||||
gf_physics_t* physics;
|
||||
gf_draw_t* draw;
|
||||
});
|
||||
#else
|
||||
typedef void gf_engine_t;
|
||||
#endif
|
||||
|
||||
#endif
|
39
engine/include/gf_type/draw.h
Normal file
39
engine/include/gf_type/draw.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef __GF_TYPE_DRAW_H__
|
||||
#define __GF_TYPE_DRAW_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
#ifdef GF_EXPOSE_DRAW
|
||||
/* External library */
|
||||
|
||||
/* Engine */
|
||||
#include <gf_type/draw_platform.h>
|
||||
#include <gf_type/draw_driver.h>
|
||||
#include <gf_type/texture.h>
|
||||
#include <gf_type/math.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
GF_DECLARE_TYPE(draw, );
|
||||
|
||||
GF_DECLARE_TYPE(draw, {
|
||||
gf_draw_platform_t* platform;
|
||||
gf_draw_driver_t* driver;
|
||||
int close;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
int running;
|
||||
gf_texture_t* font[128];
|
||||
gf_vector_t light;
|
||||
gf_vector_t lookat;
|
||||
gf_vector_t camera;
|
||||
void (*draw)(gf_draw_t*);
|
||||
});
|
||||
#else
|
||||
typedef void gf_draw_t;
|
||||
#endif
|
||||
|
||||
#endif
|
27
engine/include/gf_type/draw_driver.h
Normal file
27
engine/include/gf_type/draw_driver.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef __GF_TYPE_DRAW_DRIVER_H__
|
||||
#define __GF_TYPE_DRAW_DRIVER_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
#ifdef GF_EXPOSE_DRAW_DRIVER
|
||||
/* External library */
|
||||
#ifdef DRV_OPENGL
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
#ifdef DRV_OPENGL
|
||||
GF_DECLARE_TYPE(draw_driver, { GLUquadric* quadric; });
|
||||
GF_DECLARE_TYPE(draw_driver_texture, { GLuint id; });
|
||||
#endif
|
||||
#else
|
||||
typedef void gf_draw_driver_t;
|
||||
typedef void gf_draw_driver_texture_t;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,10 +1,10 @@
|
||||
#ifndef __NE_TYPE_DRAW_PLATFORM_H__
|
||||
#define __NE_TYPE_DRAW_PLATFORM_H__
|
||||
#ifndef __GF_TYPE_DRAW_PLATFORM_H__
|
||||
#define __GF_TYPE_DRAW_PLATFORM_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
#ifdef NE_EXPOSE_DRAW_PLATFORM
|
||||
#ifdef GF_EXPOSE_DRAW_PLATFORM
|
||||
/* External library */
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
@ -18,29 +18,29 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#endif
|
||||
|
||||
/* NishBox */
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
#if defined(USE_GLX)
|
||||
NE_DECLARE_TYPE(draw_platform, {
|
||||
GF_DECLARE_TYPE(draw_platform, {
|
||||
Display* display;
|
||||
Window window;
|
||||
GLXContext context;
|
||||
Atom wm_delete_window;
|
||||
});
|
||||
#elif defined(USE_WGL)
|
||||
NE_DECLARE_TYPE(draw_platform, {
|
||||
GF_DECLARE_TYPE(draw_platform, {
|
||||
HINSTANCE instance;
|
||||
HWND window;
|
||||
HDC dc;
|
||||
HGLRC glrc;
|
||||
});
|
||||
#elif defined(USE_GLFW)
|
||||
NE_DECLARE_TYPE(draw_platform, { GLFWwindow* window; });
|
||||
GF_DECLARE_TYPE(draw_platform, { GLFWwindow* window; });
|
||||
#endif
|
||||
#else
|
||||
typedef void ne_draw_platform_t;
|
||||
typedef void gf_draw_platform_t;
|
||||
#endif
|
||||
|
||||
#endif
|
19
engine/include/gf_type/math.h
Normal file
19
engine/include/gf_type/math.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef __GF_TYPE_MATH_H__
|
||||
#define __GF_TYPE_MATH_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
#ifdef GF_EXPOSE_MATH
|
||||
/* External library */
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
typedef double gf_vector_t[4];
|
||||
#else
|
||||
#error "should not happen!"
|
||||
#endif
|
||||
|
||||
#endif
|
29
engine/include/gf_type/mesh.h
Normal file
29
engine/include/gf_type/mesh.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef __GF_TYPE_MESH_H__
|
||||
#define __GF_TYPE_MESH_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
#ifdef GF_EXPOSE_MESH
|
||||
/* External library */
|
||||
|
||||
/* Engine */
|
||||
#include <gf_type/math.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
GF_DECLARE_TYPE(shape, {
|
||||
gf_vector_t points[3];
|
||||
gf_vector_t color;
|
||||
});
|
||||
|
||||
GF_DECLARE_TYPE(mesh, {
|
||||
gf_shape_t* shapes;
|
||||
int shape_count;
|
||||
});
|
||||
#else
|
||||
typedef void gf_mesh_t;
|
||||
typedef void gf_shape_t;
|
||||
#endif
|
||||
|
||||
#endif
|
24
engine/include/gf_type/model.h
Normal file
24
engine/include/gf_type/model.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef __GF_TYPE_MODEL_H__
|
||||
#define __GF_TYPE_MODEL_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
#ifdef GF_EXPOSE_MODEL
|
||||
/* External library */
|
||||
|
||||
/* Engine */
|
||||
#include <gf_type/mesh.h>
|
||||
#include <gf_type/texture.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
GF_DECLARE_TYPE(model, {
|
||||
gf_mesh_t* mesh;
|
||||
gf_texture_t* texture;
|
||||
});
|
||||
#else
|
||||
typedef void gf_model_t;
|
||||
#endif
|
||||
|
||||
#endif
|
20
engine/include/gf_type/physics.h
Normal file
20
engine/include/gf_type/physics.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef __GF_TYPE_PHYSICS_H__
|
||||
#define __GF_TYPE_PHYSICS_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
#ifdef GF_EXPOSE_PHYSICS
|
||||
/* External library */
|
||||
#include <ode/ode.h>
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
GF_DECLARE_TYPE(physics, { dWorldID id; });
|
||||
#else
|
||||
typedef void gf_physics_t;
|
||||
#endif
|
||||
|
||||
#endif
|
24
engine/include/gf_type/texture.h
Normal file
24
engine/include/gf_type/texture.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef __GF_TYPE_TEXTURE_H__
|
||||
#define __GF_TYPE_TEXTURE_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
#ifdef GF_EXPOSE_TEXTURE
|
||||
/* External library */
|
||||
|
||||
/* Engine */
|
||||
#include <gf_type/draw_driver.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
GF_DECLARE_TYPE(texture, {
|
||||
gf_draw_driver_texture_t* draw_driver_texture;
|
||||
int width;
|
||||
int height;
|
||||
});
|
||||
#else
|
||||
typedef void gf_texture_t;
|
||||
#endif
|
||||
|
||||
#endif
|
40
engine/include/gf_type/thread.h
Normal file
40
engine/include/gf_type/thread.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef __GF_TYPE_THREAD_H__
|
||||
#define __GF_TYPE_THREAD_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
#ifdef GF_EXPOSE_THREAD
|
||||
/* External library */
|
||||
#if defined(THREAD_POSIX)
|
||||
#include <pthread.h>
|
||||
#elif defined(THREAD_WIN32)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
GF_DECLARE_TYPE(thread_context, {
|
||||
void (*func)(void*);
|
||||
void* data;
|
||||
});
|
||||
|
||||
#if defined(THREAD_POSIX)
|
||||
GF_DECLARE_TYPE(thread, {
|
||||
gf_thread_context_t context;
|
||||
pthread_t thread;
|
||||
});
|
||||
#elif defined(THREAD_WIN32)
|
||||
GF_DECLARE_TYPE(thread, {
|
||||
gf_thread_context_t context;
|
||||
HANDLE thread;
|
||||
});
|
||||
#endif
|
||||
#else
|
||||
typedef void gf_thread_t;
|
||||
typedef void gf_thread_context_t;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,17 +1,17 @@
|
||||
#ifndef __NE_TYPE_VERSION_H__
|
||||
#define __NE_TYPE_VERSION_H__
|
||||
#ifndef __GF_TYPE_VERSION_H__
|
||||
#define __GF_TYPE_VERSION_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
#ifdef NE_EXPOSE_VERSION
|
||||
#ifdef GF_EXPOSE_VERSION
|
||||
/* External library */
|
||||
|
||||
/* NishBox */
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
NE_DECLARE_TYPE(version, {
|
||||
GF_DECLARE_TYPE(version, {
|
||||
int major;
|
||||
int minor;
|
||||
int patch;
|
16
engine/include/gf_version.h
Normal file
16
engine/include/gf_version.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef __GF_VERSION_H__
|
||||
#define __GF_VERSION_H__
|
||||
|
||||
#include <gf_pre.h>
|
||||
#include <gf_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <gf_type/version.h>
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
|
||||
void gf_get_version(gf_version_t* version);
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
#ifndef __NE_CORE_H__
|
||||
#define __NE_CORE_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <ne_type/core.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
void ne_engine_begin(void);
|
||||
void ne_engine_end(void);
|
||||
ne_engine_t* ne_engine_create(int nogui);
|
||||
void ne_engine_loop(ne_engine_t* engine);
|
||||
void ne_engine_set_draw(ne_engine_t* engine, void (*func)(ne_draw_t*));
|
||||
void ne_engine_destroy(ne_engine_t* engine);
|
||||
|
||||
#endif
|
@ -1,23 +0,0 @@
|
||||
#ifndef __NE_DRAW_H__
|
||||
#define __NE_DRAW_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <ne_type/draw.h>
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
ne_draw_t* ne_draw_create(void);
|
||||
void ne_draw_destroy(ne_draw_t* draw);
|
||||
void ne_draw_frame(ne_draw_t* draw);
|
||||
int ne_draw_step(ne_draw_t* draw);
|
||||
void ne_draw_begin(void);
|
||||
void ne_draw_end(void);
|
||||
void ne_draw_set_draw(ne_draw_t* engine, void (*func)(ne_draw_t*));
|
||||
void ne_draw_reshape(ne_draw_t* draw);
|
||||
|
||||
#endif
|
@ -1,26 +0,0 @@
|
||||
#ifndef __NE_DRAW_DRIVER_H__
|
||||
#define __NE_DRAW_DRIVER_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <ne_type/draw_driver.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
void ne_draw_driver_init(ne_draw_t* draw);
|
||||
void ne_draw_driver_destroy(ne_draw_t* draw);
|
||||
int ne_draw_driver_has_extension(ne_draw_t* draw, const char* query);
|
||||
void ne_draw_driver_reshape(ne_draw_t* draw);
|
||||
|
||||
ne_draw_driver_texture_t* ne_draw_driver_register_texture(ne_draw_t* draw, int width, int height, unsigned char* data);
|
||||
void ne_draw_driver_destroy_texture(ne_draw_driver_texture_t* texture);
|
||||
void ne_draw_driver_draw_texture(ne_draw_t* draw, float x, float y, float w, float h, ne_draw_driver_texture_t* texture, float r, float g, float b, float a);
|
||||
void ne_draw_driver_before(ne_draw_t* draw);
|
||||
void ne_draw_driver_after(ne_draw_t* draw);
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
#ifndef __NE_DRAW_PLATFORM_H__
|
||||
#define __NE_DRAW_PLATFORM_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <ne_type/draw_platform.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
void ne_draw_platform_create(ne_draw_t* draw);
|
||||
void ne_draw_platform_destroy(ne_draw_t* draw);
|
||||
int ne_draw_platform_step(ne_draw_t* draw);
|
||||
int ne_draw_platform_has_extension(ne_draw_t* draw, const char* query);
|
||||
void ne_draw_platform_begin(void);
|
||||
void ne_draw_platform_end(void);
|
||||
|
||||
#endif
|
@ -1,15 +0,0 @@
|
||||
#ifndef __NE_FONT_H__
|
||||
#define __NE_FONT_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
extern unsigned char ne_font[128][8];
|
||||
|
||||
#endif
|
@ -1,19 +0,0 @@
|
||||
#ifndef __NE_GRAPHIC_H__
|
||||
#define __NE_GRAPHIC_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
void ne_graphic_clear(ne_draw_t* draw);
|
||||
void ne_graphic_begin_2d(ne_draw_t* draw);
|
||||
void ne_graphic_end_2d(ne_draw_t* draw);
|
||||
void ne_graphic_text(ne_draw_t* draw, float x, float y, float size, const char* text, float r, float g, float b, float a);
|
||||
|
||||
#endif
|
@ -1,17 +0,0 @@
|
||||
#ifndef __NE_LOG_H__
|
||||
#define __NE_LOG_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
#define ne_function_log(fmt, arg, ...) ne_log("%6d %24s: " fmt "\n", __LINE__, __FUNCTION_NAME__, arg)
|
||||
|
||||
void ne_log(const char* fmt, ...);
|
||||
|
||||
#endif
|
@ -1,67 +0,0 @@
|
||||
#ifndef __NE_MACRO_H__
|
||||
#define __NE_MACRO_H__
|
||||
|
||||
#ifdef NE_EXPOSE_ALL
|
||||
|
||||
#ifndef NE_EXPOSE_CORE
|
||||
#define NE_EXPOSE_CORE
|
||||
#endif
|
||||
|
||||
#ifndef NE_EXPOSE_DRAW
|
||||
#define NE_EXPOSE_DRAW
|
||||
#endif
|
||||
|
||||
#ifndef NE_EXPOSE_DRAW_PLATFORM
|
||||
#define NE_EXPOSE_DRAW_PLATFORM
|
||||
#endif
|
||||
|
||||
#ifndef NE_EXPOSE_MESH
|
||||
#define NE_EXPOSE_MESH
|
||||
#endif
|
||||
|
||||
#ifndef NE_EXPOSE_MODEL
|
||||
#define NE_EXPOSE_MODEL
|
||||
#endif
|
||||
|
||||
#ifndef NE_EXPOSE_TEXTURE
|
||||
#define NE_EXPOSE_TEXTURE
|
||||
#endif
|
||||
|
||||
#ifndef NE_EXPOSE_PHYSICS
|
||||
#define NE_EXPOSE_PHYSICS
|
||||
#endif
|
||||
|
||||
#ifndef NE_EXPOSE_MATH
|
||||
#define NE_EXPOSE_MATH
|
||||
#endif
|
||||
|
||||
#ifndef NE_EXPOSE_VERSION
|
||||
#define NE_EXPOSE_VERSION
|
||||
#endif
|
||||
|
||||
#ifndef NE_EXPOSE_DRAW_DRIVER
|
||||
#define NE_EXPOSE_DRAW_DRIVER
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef __FUNCTION_NAME__
|
||||
#ifdef _MSC_VER
|
||||
#define __FUNCTION_NAME__ __FUNCTION__
|
||||
#else
|
||||
#define __FUNCTION_NAME__ __func__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define NE_DECLARE_TYPE(n, b) typedef struct _ne_##n b ne_##n##_t;
|
||||
|
||||
/* Expose them by default */
|
||||
#ifndef NE_EXPOSE_MATH
|
||||
#define NE_EXPOSE_MATH
|
||||
#endif
|
||||
|
||||
#ifndef NE_EXPOSE_VERSION
|
||||
#define NE_EXPOSE_VERSION
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
#ifndef __NE_MATH_H__
|
||||
#define __NE_MATH_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <ne_type/math.h>
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
#define NE_VECTOR_COPY(from, to) \
|
||||
to[0] = from[0]; \
|
||||
to[1] = from[1]; \
|
||||
to[2] = from[2]
|
||||
|
||||
float ne_log2(float x);
|
||||
void ne_calculate_normal(ne_vector_t* r, ne_vector_t v0, ne_vector_t v1, ne_vector_t v2);
|
||||
|
||||
#endif
|
@ -1,14 +0,0 @@
|
||||
#ifndef __NE_MESH_H__
|
||||
#define __NE_MESH_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <ne_type/mesh.h>
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
#endif
|
@ -1,14 +0,0 @@
|
||||
#ifndef __NE_MODEL_H__
|
||||
#define __NE_MODEL_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <ne_type/model.h>
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
#endif
|
@ -1,19 +0,0 @@
|
||||
#ifndef __NE_PHYSICS_H__
|
||||
#define __NE_PHYSICS_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <ne_type/physics.h>
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
void ne_physics_begin(void);
|
||||
void ne_physics_end(void);
|
||||
ne_physics_t* ne_physics_create(void);
|
||||
void ne_physics_destroy(ne_physics_t* physics);
|
||||
|
||||
#endif
|
@ -1,19 +0,0 @@
|
||||
#ifndef __NE_TEXTURE_H__
|
||||
#define __NE_TEXTURE_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <ne_type/texture.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
ne_texture_t* ne_register_texture(ne_draw_t* draw, int width, int height, unsigned char* data);
|
||||
void ne_destroy_texture(ne_texture_t* texture);
|
||||
void ne_draw_texture(ne_draw_t* draw, float x, float y, float w, float h, ne_texture_t* texture, float r, float g, float b, float a);
|
||||
|
||||
#endif
|
@ -1,18 +0,0 @@
|
||||
#ifndef __NE_THREAD_H__
|
||||
#define __NE_THREAD_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <ne_type/thread.h>
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
ne_thread_t* ne_create_thread(void (*func)(void*), void* userdata);
|
||||
void ne_join_thread(ne_thread_t* thread);
|
||||
void ne_destroy_thread(ne_thread_t* thread);
|
||||
|
||||
#endif
|
@ -1,24 +0,0 @@
|
||||
#ifndef __NE_TYPE_CORE_H__
|
||||
#define __NE_TYPE_CORE_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
#ifdef NE_EXPOSE_CORE
|
||||
/* External library */
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_type/physics.h>
|
||||
#include <ne_type/draw.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
NE_DECLARE_TYPE(engine, {
|
||||
ne_physics_t* physics;
|
||||
ne_draw_t* draw;
|
||||
});
|
||||
#else
|
||||
typedef void ne_engine_t;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,39 +0,0 @@
|
||||
#ifndef __NE_TYPE_DRAW_H__
|
||||
#define __NE_TYPE_DRAW_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
#ifdef NE_EXPOSE_DRAW
|
||||
/* External library */
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_type/draw_platform.h>
|
||||
#include <ne_type/draw_driver.h>
|
||||
#include <ne_type/texture.h>
|
||||
#include <ne_type/math.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
NE_DECLARE_TYPE(draw, );
|
||||
|
||||
NE_DECLARE_TYPE(draw, {
|
||||
ne_draw_platform_t* platform;
|
||||
ne_draw_driver_t* driver;
|
||||
int close;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
int running;
|
||||
ne_texture_t* font[128];
|
||||
ne_vector_t light;
|
||||
ne_vector_t lookat;
|
||||
ne_vector_t camera;
|
||||
void (*draw)(ne_draw_t*);
|
||||
});
|
||||
#else
|
||||
typedef void ne_draw_t;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,27 +0,0 @@
|
||||
#ifndef __NE_TYPE_DRAW_DRIVER_H__
|
||||
#define __NE_TYPE_DRAW_DRIVER_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
#ifdef NE_EXPOSE_DRAW_DRIVER
|
||||
/* External library */
|
||||
#ifdef DRV_OPENGL
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
#ifdef DRV_OPENGL
|
||||
NE_DECLARE_TYPE(draw_driver, { GLUquadric* quadric; });
|
||||
NE_DECLARE_TYPE(draw_driver_texture, { GLuint id; });
|
||||
#endif
|
||||
#else
|
||||
typedef void ne_draw_driver_t;
|
||||
typedef void ne_draw_driver_texture_t;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,19 +0,0 @@
|
||||
#ifndef __NE_TYPE_MATH_H__
|
||||
#define __NE_TYPE_MATH_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
#ifdef NE_EXPOSE_MATH
|
||||
/* External library */
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
typedef double ne_vector_t[4];
|
||||
#else
|
||||
#error "should not happen!"
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,29 +0,0 @@
|
||||
#ifndef __NE_TYPE_MESH_H__
|
||||
#define __NE_TYPE_MESH_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
#ifdef NE_EXPOSE_MESH
|
||||
/* External library */
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_type/math.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
NE_DECLARE_TYPE(shape, {
|
||||
ne_vector_t points[3];
|
||||
ne_vector_t color;
|
||||
});
|
||||
|
||||
NE_DECLARE_TYPE(mesh, {
|
||||
ne_shape_t* shapes;
|
||||
int shape_count;
|
||||
});
|
||||
#else
|
||||
typedef void ne_mesh_t;
|
||||
typedef void ne_shape_t;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,24 +0,0 @@
|
||||
#ifndef __NE_TYPE_MODEL_H__
|
||||
#define __NE_TYPE_MODEL_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
#ifdef NE_EXPOSE_MODEL
|
||||
/* External library */
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_type/mesh.h>
|
||||
#include <ne_type/texture.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
NE_DECLARE_TYPE(model, {
|
||||
ne_mesh_t* mesh;
|
||||
ne_texture_t* texture;
|
||||
});
|
||||
#else
|
||||
typedef void ne_model_t;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,20 +0,0 @@
|
||||
#ifndef __NE_TYPE_PHYSICS_H__
|
||||
#define __NE_TYPE_PHYSICS_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
#ifdef NE_EXPOSE_PHYSICS
|
||||
/* External library */
|
||||
#include <ode/ode.h>
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
NE_DECLARE_TYPE(physics, { dWorldID id; });
|
||||
#else
|
||||
typedef void ne_physics_t;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,24 +0,0 @@
|
||||
#ifndef __NE_TYPE_TEXTURE_H__
|
||||
#define __NE_TYPE_TEXTURE_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
#ifdef NE_EXPOSE_TEXTURE
|
||||
/* External library */
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_type/draw_driver.h>
|
||||
|
||||
/* Standard */
|
||||
|
||||
NE_DECLARE_TYPE(texture, {
|
||||
ne_draw_driver_texture_t* draw_driver_texture;
|
||||
int width;
|
||||
int height;
|
||||
});
|
||||
#else
|
||||
typedef void ne_texture_t;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,40 +0,0 @@
|
||||
#ifndef __NE_TYPE_THREAD_H__
|
||||
#define __NE_TYPE_THREAD_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
#ifdef NE_EXPOSE_THREAD
|
||||
/* External library */
|
||||
#if defined(THREAD_POSIX)
|
||||
#include <pthread.h>
|
||||
#elif defined(THREAD_WIN32)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
NE_DECLARE_TYPE(thread_context, {
|
||||
void (*func)(void*);
|
||||
void* data;
|
||||
});
|
||||
|
||||
#if defined(THREAD_POSIX)
|
||||
NE_DECLARE_TYPE(thread, {
|
||||
ne_thread_context_t context;
|
||||
pthread_t thread;
|
||||
});
|
||||
#elif defined(THREAD_WIN32)
|
||||
NE_DECLARE_TYPE(thread, {
|
||||
ne_thread_context_t context;
|
||||
HANDLE thread;
|
||||
});
|
||||
#endif
|
||||
#else
|
||||
typedef void ne_thread_t;
|
||||
typedef void ne_thread_context_t;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,16 +0,0 @@
|
||||
#ifndef __NE_VERSION_H__
|
||||
#define __NE_VERSION_H__
|
||||
|
||||
#include <ne_pre.h>
|
||||
#include <ne_macro.h>
|
||||
|
||||
/* Type */
|
||||
#include <ne_type/version.h>
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
|
||||
void ne_get_version(ne_version_t* version);
|
||||
|
||||
#endif
|
@ -1,94 +0,0 @@
|
||||
#define NE_EXPOSE_CORE
|
||||
|
||||
#include <ne_pre.h>
|
||||
|
||||
/* External library */
|
||||
#ifdef _WIN32
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
|
||||
/* Interface */
|
||||
#include <ne_core.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_draw.h>
|
||||
#include <ne_physics.h>
|
||||
#include <ne_log.h>
|
||||
#include <ne_version.h>
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void ne_engine_begin(void) {
|
||||
ne_version_t ver;
|
||||
#ifdef _WIN32
|
||||
WSADATA wsa;
|
||||
#endif
|
||||
ne_get_version(&ver);
|
||||
ne_function_log("NishEngine %s", ver.full);
|
||||
ne_function_log("Lua %s", ver.lua);
|
||||
ne_function_log("zlib %s", ver.zlib);
|
||||
ne_function_log("Thread model: %s", ver.thread);
|
||||
ne_function_log("OpenGL backend: %s", ver.opengl);
|
||||
#ifdef _WIN32
|
||||
WSAStartup(MAKEWORD(1, 1), &wsa);
|
||||
ne_function_log("Winsock ready", "");
|
||||
#endif
|
||||
ne_draw_begin();
|
||||
ne_physics_begin();
|
||||
}
|
||||
|
||||
void ne_engine_end(void) {
|
||||
ne_physics_end();
|
||||
ne_draw_end();
|
||||
}
|
||||
|
||||
ne_engine_t* ne_engine_create(int nogui) {
|
||||
ne_engine_t* engine = malloc(sizeof(*engine));
|
||||
memset(engine, 0, sizeof(*engine));
|
||||
if(nogui) {
|
||||
ne_function_log("No GUI mode", "");
|
||||
engine->draw = NULL;
|
||||
} else {
|
||||
ne_function_log("GUI mode", "");
|
||||
engine->draw = ne_draw_create();
|
||||
if(engine->draw == NULL) {
|
||||
ne_function_log("Failed to create drawing interface", "");
|
||||
free(engine);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
engine->physics = ne_physics_create();
|
||||
return engine;
|
||||
}
|
||||
|
||||
void ne_engine_set_draw(ne_engine_t* engine, void (*func)(ne_draw_t*)) { ne_draw_set_draw(engine->draw, func); }
|
||||
|
||||
/**
|
||||
* Writing this so I don't forget
|
||||
*
|
||||
* 1. Calls ne_draw_step
|
||||
* 2. ne_draw_step calls _ne_draw_step (Platform-dependent)
|
||||
* 3. _ne_draw_step processes platform-dependent stuffs (e.g. events)
|
||||
* 4. _ne_draw_step calls ne_draw_driver_before
|
||||
* 4. _ne_draw_step calls ne_draw_frame
|
||||
* 5. ne_draw_frame draws frame
|
||||
* 4. _ne_draw_step calls ne_draw_driver_after
|
||||
* 6. _ne_draw_step swaps buffers
|
||||
* 7. Comes back here
|
||||
*/
|
||||
void ne_engine_loop(ne_engine_t* engine) {
|
||||
while(1) {
|
||||
if(engine->draw != NULL) {
|
||||
if(ne_draw_step(engine->draw) != 0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ne_engine_destroy(ne_engine_t* engine) {
|
||||
if(engine->physics != NULL) ne_physics_destroy(engine->physics);
|
||||
if(engine->draw != NULL) ne_draw_destroy(engine->draw);
|
||||
free(engine);
|
||||
ne_function_log("Destroyed engine", "");
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
#define NE_EXPOSE_DRAW
|
||||
|
||||
#include <ne_pre.h>
|
||||
|
||||
/* External library */
|
||||
|
||||
/* Interface */
|
||||
#include <ne_draw.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_log.h>
|
||||
#include <ne_draw_platform.h>
|
||||
#include <ne_draw_driver.h>
|
||||
#include <ne_graphic.h>
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
void ne_draw_begin(void) { ne_draw_platform_begin(); }
|
||||
|
||||
void ne_draw_end(void) { ne_draw_platform_end(); }
|
||||
|
||||
ne_draw_t* ne_draw_create(void) {
|
||||
ne_draw_t* draw = malloc(sizeof(*draw));
|
||||
memset(draw, 0, sizeof(*draw));
|
||||
draw->x = 0;
|
||||
draw->y = 0;
|
||||
draw->width = 640;
|
||||
draw->height = 480;
|
||||
draw->running = 0;
|
||||
ne_draw_platform_create(draw);
|
||||
if(draw->platform != NULL) {
|
||||
ne_function_log("Created drawing interface successfully", "");
|
||||
ne_draw_driver_init(draw);
|
||||
ne_draw_reshape(draw);
|
||||
draw->running = 1;
|
||||
|
||||
draw->light[0] = 10.0;
|
||||
draw->light[1] = 10.0;
|
||||
draw->light[2] = 0.0;
|
||||
draw->light[3] = 1.0;
|
||||
|
||||
draw->camera[0] = 0;
|
||||
draw->camera[1] = 10;
|
||||
draw->camera[2] = 0;
|
||||
|
||||
draw->lookat[0] = 0;
|
||||
draw->lookat[1] = 0;
|
||||
draw->lookat[2] = 0;
|
||||
}
|
||||
return draw;
|
||||
}
|
||||
|
||||
void ne_draw_reshape(ne_draw_t* draw) { ne_draw_driver_reshape(draw); }
|
||||
|
||||
/* Runs every frame */
|
||||
void ne_draw_frame(ne_draw_t* draw) {
|
||||
if(draw->draw != NULL) draw->draw(draw);
|
||||
}
|
||||
|
||||
void ne_draw_set_draw(ne_draw_t* draw, void (*func)(ne_draw_t*)) { draw->draw = func; }
|
||||
|
||||
int ne_draw_step(ne_draw_t* draw) {
|
||||
int ret = ne_draw_platform_step(draw);
|
||||
if(ret != 0) return ret;
|
||||
draw->close = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ne_draw_destroy(ne_draw_t* draw) {
|
||||
int i;
|
||||
if(draw->running) {
|
||||
ne_draw_driver_destroy(draw);
|
||||
}
|
||||
ne_draw_platform_destroy(draw);
|
||||
ne_function_log("Destroyed drawing interface", "");
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#define NE_EXPOSE_MESH
|
||||
|
||||
#include <ne_pre.h>
|
||||
|
||||
/* External library */
|
||||
|
||||
/* Interface */
|
||||
#include <ne_mesh.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_math.h>
|
||||
|
||||
/* Standard */
|
@ -1,13 +0,0 @@
|
||||
#define NE_EXPOSE_MODEL
|
||||
|
||||
#include <ne_pre.h>
|
||||
|
||||
/* External library */
|
||||
|
||||
/* Interface */
|
||||
#include <ne_model.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_math.h>
|
||||
|
||||
/* Standard */
|
@ -1,32 +0,0 @@
|
||||
#define NE_EXPOSE_PHYSICS
|
||||
|
||||
#include <ne_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <ode/ode.h>
|
||||
|
||||
/* Interface */
|
||||
#include <ne_physics.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_log.h>
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
|
||||
void ne_physics_begin(void) { dInitODE(); }
|
||||
|
||||
void ne_physics_end(void) { dCloseODE(); }
|
||||
|
||||
ne_physics_t* ne_physics_create(void) {
|
||||
ne_physics_t* physics = malloc(sizeof(*physics));
|
||||
physics->id = dWorldCreate();
|
||||
dWorldSetGravity(physics->id, 0, 0, -9.81);
|
||||
return physics;
|
||||
}
|
||||
|
||||
void ne_physics_destroy(ne_physics_t* physics) {
|
||||
dWorldDestroy(physics->id);
|
||||
free(physics);
|
||||
ne_function_log("Destroyed physics", "");
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
#define NE_EXPOSE_TEXTURE
|
||||
|
||||
#include <ne_pre.h>
|
||||
|
||||
/* External library */
|
||||
|
||||
/* Interface */
|
||||
#include <ne_texture.h>
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_draw_driver.h>
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
|
||||
ne_texture_t* ne_register_texture(ne_draw_t* draw, int width, int height, unsigned char* data) {
|
||||
ne_texture_t* texture = malloc(sizeof(*texture));
|
||||
ne_draw_driver_texture_t* ddtexture = ne_draw_driver_register_texture(draw, width, height, data);
|
||||
if(ddtexture == NULL) {
|
||||
free(texture);
|
||||
return NULL;
|
||||
}
|
||||
texture->width = width;
|
||||
texture->height = height;
|
||||
texture->draw_driver_texture = ddtexture;
|
||||
return texture;
|
||||
}
|
||||
|
||||
void ne_destroy_texture(ne_texture_t* texture) {
|
||||
ne_draw_driver_destroy_texture(texture->draw_driver_texture);
|
||||
free(texture);
|
||||
}
|
||||
|
||||
void ne_draw_texture(ne_draw_t* draw, float x, float y, float w, float h, ne_texture_t* texture, float r, float g, float b, float a) { ne_draw_driver_draw_texture(draw, x, y, w, h, texture->draw_driver_texture, r, g, b, a); }
|
36
engine/thread/posix/gf_thread.c
Normal file
36
engine/thread/posix/gf_thread.c
Normal file
@ -0,0 +1,36 @@
|
||||
#define GF_EXPOSE_THREAD
|
||||
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <pthread.h>
|
||||
|
||||
/* Interface */
|
||||
#include <gf_thread.h>
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
|
||||
void* gf_wrap_thread(void* arg) {
|
||||
gf_thread_context_t* ctx = (gf_thread_context_t*)arg;
|
||||
ctx->func(ctx->data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gf_thread_t* gf_create_thread(void (*func)(void*), void* userdata) {
|
||||
gf_thread_t* thread = malloc(sizeof(*thread));
|
||||
thread->context.func = func;
|
||||
thread->context.data = userdata;
|
||||
if(pthread_create(&thread->thread, NULL, gf_wrap_thread, &thread->context) == 0) return thread;
|
||||
free(thread);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void gf_join_thread(gf_thread_t* thread) {
|
||||
void* value;
|
||||
pthread_join(thread->thread, &value);
|
||||
}
|
||||
|
||||
void gf_destroy_thread(gf_thread_t* thread) { free(thread); }
|
@ -1,36 +0,0 @@
|
||||
#define NE_EXPOSE_THREAD
|
||||
|
||||
#include <ne_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <pthread.h>
|
||||
|
||||
/* Interface */
|
||||
#include <ne_thread.h>
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
|
||||
void* ne_wrap_thread(void* arg) {
|
||||
ne_thread_context_t* ctx = (ne_thread_context_t*)arg;
|
||||
ctx->func(ctx->data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ne_thread_t* ne_create_thread(void (*func)(void*), void* userdata) {
|
||||
ne_thread_t* thread = malloc(sizeof(*thread));
|
||||
thread->context.func = func;
|
||||
thread->context.data = userdata;
|
||||
if(pthread_create(&thread->thread, NULL, ne_wrap_thread, &thread->context) == 0) return thread;
|
||||
free(thread);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ne_join_thread(ne_thread_t* thread) {
|
||||
void* value;
|
||||
pthread_join(thread->thread, &value);
|
||||
}
|
||||
|
||||
void ne_destroy_thread(ne_thread_t* thread) { free(thread); }
|
36
engine/thread/win32/gf_thread.c
Normal file
36
engine/thread/win32/gf_thread.c
Normal file
@ -0,0 +1,36 @@
|
||||
#define GF_EXPOSE_THREAD
|
||||
|
||||
#include <gf_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <windows.h>
|
||||
|
||||
/* Interface */
|
||||
#include <gf_thread.h>
|
||||
|
||||
/* Engine */
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
|
||||
DWORD WINAPI gf_wrap_thread(void* arg) {
|
||||
gf_thread_context_t* ctx = (gf_thread_context_t*)arg;
|
||||
ctx->func(ctx->data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gf_thread_t* gf_create_thread(void (*func)(void*), void* userdata) {
|
||||
gf_thread_t* thread = malloc(sizeof(*thread));
|
||||
thread->context.func = func;
|
||||
thread->context.data = userdata;
|
||||
if((thread->thread = CreateThread(NULL, 0, gf_wrap_thread, &thread->context, 0, NULL)) != NULL) return thread;
|
||||
free(thread);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void gf_join_thread(gf_thread_t* thread) { WaitForSingleObject(thread->thread, INFINITE); }
|
||||
|
||||
void gf_destroy_thread(gf_thread_t* thread) {
|
||||
CloseHandle(thread->thread);
|
||||
free(thread);
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
#define NE_EXPOSE_THREAD
|
||||
|
||||
#include <ne_pre.h>
|
||||
|
||||
/* External library */
|
||||
#include <windows.h>
|
||||
|
||||
/* Interface */
|
||||
#include <ne_thread.h>
|
||||
|
||||
/* NishBox */
|
||||
|
||||
/* Standard */
|
||||
#include <stdlib.h>
|
||||
|
||||
DWORD WINAPI ne_wrap_thread(void* arg) {
|
||||
ne_thread_context_t* ctx = (ne_thread_context_t*)arg;
|
||||
ctx->func(ctx->data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ne_thread_t* ne_create_thread(void (*func)(void*), void* userdata) {
|
||||
ne_thread_t* thread = malloc(sizeof(*thread));
|
||||
thread->context.func = func;
|
||||
thread->context.data = userdata;
|
||||
if((thread->thread = CreateThread(NULL, 0, ne_wrap_thread, &thread->context, 0, NULL)) != NULL) return thread;
|
||||
free(thread);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ne_join_thread(ne_thread_t* thread) { WaitForSingleObject(thread->thread, INFINITE); }
|
||||
|
||||
void ne_destroy_thread(ne_thread_t* thread) {
|
||||
CloseHandle(thread->thread);
|
||||
free(thread);
|
||||
}
|
@ -220,7 +220,7 @@ project("Engine")
|
||||
optimize("On")
|
||||
filter({})
|
||||
targetdir("lib")
|
||||
targetname("nishengine")
|
||||
targetname("goldfish")
|
||||
includedirs({
|
||||
"engine/include",
|
||||
"external/lua",
|
||||
@ -242,11 +242,11 @@ project("Engine")
|
||||
|
||||
filter("system:windows")
|
||||
files({
|
||||
"engine/thread/win32/ne_thread.c"
|
||||
"engine/thread/win32/gf_thread.c"
|
||||
})
|
||||
filter("system:not windows")
|
||||
files({
|
||||
"engine/thread/posix/ne_thread.c"
|
||||
"engine/thread/posix/gf_thread.c"
|
||||
})
|
||||
filter({})
|
||||
|
||||
|
28
src/main.c
28
src/main.c
@ -1,8 +1,8 @@
|
||||
#define NE_EXPOSE_DRAW
|
||||
#define GF_EXPOSE_DRAW
|
||||
|
||||
/* NishBox */
|
||||
#include <ne_core.h>
|
||||
#include <ne_graphic.h>
|
||||
/* Engine */
|
||||
#include <gf_core.h>
|
||||
#include <gf_graphic.h>
|
||||
|
||||
/* External library */
|
||||
|
||||
@ -10,9 +10,9 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
ne_engine_t* engine;
|
||||
gf_engine_t* engine;
|
||||
|
||||
void draw_frame(ne_draw_t* draw) {
|
||||
void draw_frame(gf_draw_t* draw) {
|
||||
char d[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
char str[2];
|
||||
str[1] = 0;
|
||||
@ -26,7 +26,7 @@ void draw_frame(ne_draw_t* draw) {
|
||||
for(y = 0; y < draw->height; y += s) {
|
||||
for(x = 0; x < draw->width; x += s / 2) {
|
||||
str[0] = d[(i++) % strlen(d)];
|
||||
ne_graphic_text(draw, x, y, s, str, 255 / max * r, 255 / max * g, 255 / max * b, 255);
|
||||
gf_graphic_text(draw, x, y, s, str, 255 / max * r, 255 / max * g, 255 / max * b, 255);
|
||||
|
||||
b++;
|
||||
if(b == max + 1){
|
||||
@ -45,17 +45,17 @@ void draw_frame(ne_draw_t* draw) {
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
ne_engine_begin();
|
||||
engine = ne_engine_create(0);
|
||||
gf_engine_begin();
|
||||
engine = gf_engine_create(0);
|
||||
if(engine == NULL) {
|
||||
fprintf(stderr, "Engine creation failure\n");
|
||||
ne_engine_end();
|
||||
gf_engine_end();
|
||||
return 1;
|
||||
}
|
||||
ne_engine_set_draw(engine, draw_frame);
|
||||
ne_engine_loop(engine);
|
||||
ne_engine_destroy(engine);
|
||||
ne_engine_end();
|
||||
gf_engine_set_draw(engine, draw_frame);
|
||||
gf_engine_loop(engine);
|
||||
gf_engine_destroy(engine);
|
||||
gf_engine_end();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user