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