use bool
This commit is contained in:
parent
c7bfbf72db
commit
f86e26cddd
11 changed files with 69 additions and 46 deletions
|
|
@ -33,6 +33,22 @@ static void tick(void){
|
||||||
while(!window->close && MwPending(window)) MwStep(window);
|
while(!window->close && MwPending(window)) MwStep(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GSVector3 rot = {0, 0, 0};
|
||||||
|
static GSModel model = NULL;
|
||||||
|
|
||||||
|
static void render(GSEngine engine){
|
||||||
|
GSGL gl = GSClientGetGL(GSEngineGetClient(engine));
|
||||||
|
|
||||||
|
GSGLPushMatrix(gl);
|
||||||
|
GSGLSetRotation(gl, rot);
|
||||||
|
if(model != NULL) GSModelDraw(model);
|
||||||
|
GSGLPopMatrix(gl);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void after_render(GSEngine engine){
|
||||||
|
rot[0] = rot[1] = rot[2]++;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv){
|
int main(int argc, char** argv){
|
||||||
GSEngineParam param;
|
GSEngineParam param;
|
||||||
GSEngine engine;
|
GSEngine engine;
|
||||||
|
|
@ -43,10 +59,16 @@ int main(int argc, char** argv){
|
||||||
param.get_tick = MwTimeGetTick;
|
param.get_tick = MwTimeGetTick;
|
||||||
param.sleep = MwTimeSleep;
|
param.sleep = MwTimeSleep;
|
||||||
param.gl_swapbuffer = gl_swapbuffer;
|
param.gl_swapbuffer = gl_swapbuffer;
|
||||||
|
param.render = render;
|
||||||
|
param.after_render = after_render;
|
||||||
|
|
||||||
GSInit();
|
GSInit();
|
||||||
|
|
||||||
if((engine = GSEngineCreate(¶m)) != NULL){
|
if((engine = GSEngineCreate(¶m)) != NULL){
|
||||||
|
model = GSModelOpen(engine, "game:/mdl/crate.gsm");
|
||||||
|
|
||||||
|
GSClientToggleSkybox(GSEngineGetClient(engine), GSTrue);
|
||||||
|
|
||||||
GSEngineLoop(engine);
|
GSEngineLoop(engine);
|
||||||
GSEngineDestroy(engine);
|
GSEngineDestroy(engine);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ extern "C" {
|
||||||
GSDECL GSClient GSClientCreate(GSEngine engine);
|
GSDECL GSClient GSClientCreate(GSEngine engine);
|
||||||
GSDECL void GSClientDestroy(GSClient client);
|
GSDECL void GSClientDestroy(GSClient client);
|
||||||
GSDECL void GSClientStep(GSClient client);
|
GSDECL void GSClientStep(GSClient client);
|
||||||
|
GSDECL GSGL GSClientGetGL(GSClient client);
|
||||||
|
GSDECL void GSClientToggleSkybox(GSClient client, GSBool toggle);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ GSDECL void GSEngineParamInit(GSEngineParam* param);
|
||||||
GSDECL void GSEngineLoop(GSEngine engine);
|
GSDECL void GSEngineLoop(GSEngine engine);
|
||||||
GSDECL GSClient GSEngineGetClient(GSEngine engine);
|
GSDECL GSClient GSEngineGetClient(GSEngine engine);
|
||||||
GSDECL GSServer GSEngineGetServer(GSEngine engine);
|
GSDECL GSServer GSEngineGetServer(GSEngine engine);
|
||||||
GSDECL int GSEngineRegisterResource(GSEngine engine, const char* name, const char* path);
|
GSDECL GSBool GSEngineRegisterResource(GSEngine engine, const char* name, const char* path);
|
||||||
GSDECL void GSEngineUnregisterResource(GSEngine engine, const char* name);
|
GSDECL void GSEngineUnregisterResource(GSEngine engine, const char* name);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ extern "C" {
|
||||||
#define GSGLMaxDistance 100.0
|
#define GSGLMaxDistance 100.0
|
||||||
|
|
||||||
/* gl_shader.c */
|
/* gl_shader.c */
|
||||||
GSDECL int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs);
|
GSDECL GSBool GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs);
|
||||||
|
|
||||||
/* gl_texture.c */
|
/* gl_texture.c */
|
||||||
GSDECL void GSGLTexturePrepare(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height);
|
GSDECL void GSGLTexturePrepare(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height);
|
||||||
|
|
@ -21,12 +21,12 @@ GSDECL void GSGLTextureSet(GSGL gl, GLuint texture);
|
||||||
GSDECL void GSGLTextureDelete(GSGL gl, GLuint texture);
|
GSDECL void GSGLTextureDelete(GSGL gl, GLuint texture);
|
||||||
|
|
||||||
/* gl_common.c */
|
/* gl_common.c */
|
||||||
GSDECL int GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename);
|
GSDECL GSBool GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename);
|
||||||
GSDECL int GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix);
|
GSDECL GSBool GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix);
|
||||||
|
|
||||||
/* gl_shadow.c */
|
/* gl_shadow.c */
|
||||||
GSDECL void GSGLShadowInit(GSGL gl);
|
GSDECL void GSGLShadowInit(GSGL gl);
|
||||||
GSDECL int GSGLShadowBeforeMapping(GSGL gl);
|
GSDECL GSBool GSGLShadowBeforeMapping(GSGL gl);
|
||||||
GSDECL void GSGLShadowAfterMapping(GSGL gl);
|
GSDECL void GSGLShadowAfterMapping(GSGL gl);
|
||||||
GSDECL void GSGLShadowEnd(GSGL gl);
|
GSDECL void GSGLShadowEnd(GSGL gl);
|
||||||
GSDECL void GSGLShadowDeinit(GSGL gl);
|
GSDECL void GSGLShadowDeinit(GSGL gl);
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,8 @@ typedef void (*GSReadyCallback)(int width, int height);
|
||||||
typedef void (*GSTickCallback)(void);
|
typedef void (*GSTickCallback)(void);
|
||||||
typedef long (*GSGetTickCallback)(void);
|
typedef long (*GSGetTickCallback)(void);
|
||||||
typedef void (*GSSleepCallback)(int ms);
|
typedef void (*GSSleepCallback)(int ms);
|
||||||
|
typedef void (*GSRenderCallback)(GSEngine engine);
|
||||||
|
typedef void (*GSAfterRenderCallback)(GSEngine engine);
|
||||||
|
|
||||||
struct _GSResourceKV {
|
struct _GSResourceKV {
|
||||||
char* key;
|
char* key;
|
||||||
|
|
@ -107,6 +109,7 @@ struct _GSClient {
|
||||||
GSVector3 camera;
|
GSVector3 camera;
|
||||||
GSVector4 light0;
|
GSVector4 light0;
|
||||||
GSSkyBox skybox;
|
GSSkyBox skybox;
|
||||||
|
GSBool skybox_enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GSSkyBox {
|
struct _GSSkyBox {
|
||||||
|
|
@ -190,6 +193,8 @@ struct _GSEngineParam {
|
||||||
GSTickCallback tick;
|
GSTickCallback tick;
|
||||||
GSGetTickCallback get_tick;
|
GSGetTickCallback get_tick;
|
||||||
GSSleepCallback sleep;
|
GSSleepCallback sleep;
|
||||||
|
GSRenderCallback render;
|
||||||
|
GSAfterRenderCallback after_render;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ GSClient GSClientCreate(GSEngine engine) {
|
||||||
client->light0[2] = 5;
|
client->light0[2] = 5;
|
||||||
client->light0[3] = 1;
|
client->light0[3] = 1;
|
||||||
|
|
||||||
|
client->skybox_enabled = GSFalse;
|
||||||
|
|
||||||
client->gl = GSGLCreate(client);
|
client->gl = GSGLCreate(client);
|
||||||
|
|
||||||
client->skybox = GSSkyBoxTry(client, "default");
|
client->skybox = GSSkyBoxTry(client, "default");
|
||||||
|
|
@ -43,20 +45,8 @@ void GSClientDestroy(GSClient client) {
|
||||||
GSLog(GSLogInfo, "Destroyed client");
|
GSLog(GSLogInfo, "Destroyed client");
|
||||||
}
|
}
|
||||||
|
|
||||||
GSModel m = NULL;
|
|
||||||
GSVector3 rot = {0, 0, 0};
|
|
||||||
|
|
||||||
static void scene(GSClient client) {
|
static void scene(GSClient client) {
|
||||||
if(m == NULL) m = GSModelOpen(client->engine, "game:/mdl/crate.gsm");
|
if(client->engine->param->render != NULL) client->engine->param->render(client->engine);
|
||||||
|
|
||||||
rot[0]++;
|
|
||||||
rot[1]++;
|
|
||||||
rot[2]++;
|
|
||||||
|
|
||||||
GSGLPushMatrix(client->gl);
|
|
||||||
GSGLSetRotation(client->gl, rot);
|
|
||||||
GSModelDraw(m);
|
|
||||||
GSGLPopMatrix(client->gl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSClientStep(GSClient client) {
|
void GSClientStep(GSClient client) {
|
||||||
|
|
@ -71,17 +61,21 @@ void GSClientStep(GSClient client) {
|
||||||
GSGLShadowAfterMapping(client->gl);
|
GSGLShadowAfterMapping(client->gl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(client->skybox != NULL) GSSkyBoxDraw(client->skybox);
|
if(client->skybox_enabled){
|
||||||
|
if(client->skybox != NULL) GSSkyBoxDraw(client->skybox);
|
||||||
|
}
|
||||||
scene(client);
|
scene(client);
|
||||||
GSGLShadowEnd(client->gl);
|
GSGLShadowEnd(client->gl);
|
||||||
|
|
||||||
client->engine->param->gl_swapbuffer();
|
client->engine->param->gl_swapbuffer();
|
||||||
|
|
||||||
client->look_at[0] = 5 + cos(r) * 5;
|
if(client->engine->param->after_render != NULL) client->engine->param->after_render(client->engine);
|
||||||
client->look_at[2] = 5 + sin(r) * 5;
|
}
|
||||||
|
|
||||||
client->look_at[0] = 0;
|
GSGL GSClientGetGL(GSClient client){
|
||||||
client->look_at[2] = 0;
|
return client->gl;
|
||||||
|
}
|
||||||
r += 0.1;
|
|
||||||
|
void GSClientToggleSkybox(GSClient client, GSBool toggle){
|
||||||
|
client->skybox_enabled = toggle;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,17 @@ void GSInit(void) {
|
||||||
GSLog(GSLogInfo, "GearSrc Engine %s", version.string);
|
GSLog(GSLogInfo, "GearSrc Engine %s", version.string);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GSEngineRegisterResource(GSEngine engine, const char* name, const char* path) {
|
GSBool GSEngineRegisterResource(GSEngine engine, const char* name, const char* path) {
|
||||||
GSResource resource;
|
GSResource resource;
|
||||||
if((resource = GSResourceOpen(engine, path)) != NULL) {
|
if((resource = GSResourceOpen(engine, path)) != NULL) {
|
||||||
shput(engine->resource, name, resource);
|
shput(engine->resource, name, resource);
|
||||||
|
|
||||||
GSLog(GSLogInfo, "Registered resource %s as %s", path, name);
|
GSLog(GSLogInfo, "Registered resource %s as %s", path, name);
|
||||||
|
|
||||||
return 1;
|
return GSTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return GSFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSEngineUnregisterResource(GSEngine engine, const char* name) {
|
void GSEngineUnregisterResource(GSEngine engine, const char* name) {
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,15 @@
|
||||||
|
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
|
|
||||||
int GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename) {
|
GSBool GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename) {
|
||||||
GSFile f = GSFileOpen(gl->engine, filename);
|
GSFile f = GSFileOpen(gl->engine, filename);
|
||||||
unsigned char* data;
|
unsigned char* data;
|
||||||
unsigned char* rgba;
|
unsigned char* rgba;
|
||||||
unsigned long sz;
|
unsigned long sz;
|
||||||
int ch;
|
int ch;
|
||||||
int st = 1;
|
GSBool st = GSTrue;
|
||||||
int w, h;
|
int w, h;
|
||||||
if(f == NULL) return 0;
|
if(f == NULL) return GSFalse;
|
||||||
|
|
||||||
sz = GSFileSize(f);
|
sz = GSFileSize(f);
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ int GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const
|
||||||
GSFileClose(f);
|
GSFileClose(f);
|
||||||
|
|
||||||
if((rgba = stbi_load_from_memory(data, sz, &w, &h, &ch, 4)) == NULL) {
|
if((rgba = stbi_load_from_memory(data, sz, &w, &h, &ch, 4)) == NULL) {
|
||||||
st = 0;
|
st = GSFalse;
|
||||||
} else {
|
} else {
|
||||||
GSGLTexturePrepare(gl, texture, rgba, w, h);
|
GSGLTexturePrepare(gl, texture, rgba, w, h);
|
||||||
|
|
||||||
|
|
@ -37,12 +37,12 @@ int GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix) {
|
GSBool GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix) {
|
||||||
char* png = GSStringConcat(prefix, ".png");
|
char* png = GSStringConcat(prefix, ".png");
|
||||||
char* bmp = GSStringConcat(prefix, ".bmp");
|
char* bmp = GSStringConcat(prefix, ".bmp");
|
||||||
char* jpg = GSStringConcat(prefix, ".jpg");
|
char* jpg = GSStringConcat(prefix, ".jpg");
|
||||||
char* jpeg = GSStringConcat(prefix, ".jpeg");
|
char* jpeg = GSStringConcat(prefix, ".jpeg");
|
||||||
int st = 1;
|
GSBool st = GSTrue;
|
||||||
|
|
||||||
if(GSGLTextureLoadFile(gl, texture, width, height, prefix)) {
|
if(GSGLTextureLoadFile(gl, texture, width, height, prefix)) {
|
||||||
} else if(GSGLTextureLoadFile(gl, texture, width, height, png)) {
|
} else if(GSGLTextureLoadFile(gl, texture, width, height, png)) {
|
||||||
|
|
@ -50,7 +50,7 @@ int GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char
|
||||||
} else if(GSGLTextureLoadFile(gl, texture, width, height, jpg)) {
|
} else if(GSGLTextureLoadFile(gl, texture, width, height, jpg)) {
|
||||||
} else if(GSGLTextureLoadFile(gl, texture, width, height, jpeg)) {
|
} else if(GSGLTextureLoadFile(gl, texture, width, height, jpeg)) {
|
||||||
} else {
|
} else {
|
||||||
st = 0;
|
st = GSFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(jpeg);
|
free(jpeg);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ static void err(const char* path, GLuint shader) {
|
||||||
free(e);
|
free(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) {
|
GSBool GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) {
|
||||||
GLuint vsi;
|
GLuint vsi;
|
||||||
GLuint fsi;
|
GLuint fsi;
|
||||||
GSFile f;
|
GSFile f;
|
||||||
|
|
@ -29,7 +29,7 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) {
|
||||||
char* fss;
|
char* fss;
|
||||||
GLint st;
|
GLint st;
|
||||||
|
|
||||||
if(glUseProgram == NULL) return 0;
|
if(glUseProgram == NULL) return GSFalse;
|
||||||
|
|
||||||
if((f = GSFileOpen(gl->engine, vs)) != NULL) {
|
if((f = GSFileOpen(gl->engine, vs)) != NULL) {
|
||||||
int sz = GSFileSize(f);
|
int sz = GSFileSize(f);
|
||||||
|
|
@ -40,7 +40,7 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) {
|
||||||
|
|
||||||
GSFileClose(f);
|
GSFileClose(f);
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return GSFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((f = GSFileOpen(gl->engine, fs)) != NULL) {
|
if((f = GSFileOpen(gl->engine, fs)) != NULL) {
|
||||||
|
|
@ -54,7 +54,7 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) {
|
||||||
} else {
|
} else {
|
||||||
free(vss);
|
free(vss);
|
||||||
|
|
||||||
return 0;
|
return GSFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
vsi = glCreateShader(GL_VERTEX_SHADER);
|
vsi = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
|
@ -72,7 +72,7 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) {
|
||||||
glDeleteShader(fsi);
|
glDeleteShader(fsi);
|
||||||
free(vss);
|
free(vss);
|
||||||
free(fss);
|
free(fss);
|
||||||
return 0;
|
return GSFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
glCompileShader(fsi);
|
glCompileShader(fsi);
|
||||||
|
|
@ -84,7 +84,7 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) {
|
||||||
glDeleteShader(fsi);
|
glDeleteShader(fsi);
|
||||||
free(vss);
|
free(vss);
|
||||||
free(fss);
|
free(fss);
|
||||||
return 0;
|
return GSFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(vss);
|
free(vss);
|
||||||
|
|
@ -102,8 +102,8 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) {
|
||||||
glGetProgramiv(*shader, GL_LINK_STATUS, &st);
|
glGetProgramiv(*shader, GL_LINK_STATUS, &st);
|
||||||
if(!st) {
|
if(!st) {
|
||||||
glDeleteProgram(*shader);
|
glDeleteProgram(*shader);
|
||||||
return 0;
|
return GSFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return GSTrue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,10 @@ void GSGLShadowInit(GSGL gl) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GSGLShadowBeforeMapping(GSGL gl) {
|
GSBool GSGLShadowBeforeMapping(GSGL gl) {
|
||||||
GSVector3 zero = {0, 0, 0};
|
GSVector3 zero = {0, 0, 0};
|
||||||
|
|
||||||
if(!gl->shadow_use_shader) return 0;
|
if(!gl->shadow_use_shader) return GSFalse;
|
||||||
|
|
||||||
GSGLClear(gl);
|
GSGLClear(gl);
|
||||||
|
|
||||||
|
|
@ -76,7 +76,7 @@ int GSGLShadowBeforeMapping(GSGL gl) {
|
||||||
glPolygonOffset(1.1f, 4.0f);
|
glPolygonOffset(1.1f, 4.0f);
|
||||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
|
||||||
return 1;
|
return GSTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSGLShadowAfterMapping(GSGL gl) {
|
void GSGLShadowAfterMapping(GSGL gl) {
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit eb50af2b815f7241d79233cd38c8a0186b3d2a6b
|
Subproject commit b458613f87b1cfcf05e0cf102688814861010d9f
|
||||||
Loading…
Add table
Add a link
Reference in a new issue