diff --git a/client/main.c b/client/main.c index dead48c..bdbb981 100644 --- a/client/main.c +++ b/client/main.c @@ -44,6 +44,16 @@ static GSModel model = NULL; static void render(GSEngine self){ GSGL gl = GSClientGetGL(GSEngineGetClient(self)); + GSVector3 v[] = { + {-5, -2, 5}, + {-5, -2, -5}, + {5, -2, -5}, + {5, -2, 5} + }; + GSVector3 n = {0, 1, 0}; + GSVector4 col = {1, 1, 1, 1}; + GSVector4 col2 = {1, 0, 0, 1}; + int i, j; pos[1] = 0; @@ -60,6 +70,25 @@ static void render(GSEngine self){ GSGLSetRotation(gl, rot); if(model != NULL) GSModelDraw(model); GSGLPopMatrix(gl); + + for(i = -1; i <= 1; i++){ + for(j = -1; j <= 1; j++){ + GSVector3 pos2; + + pos2[0] = i; + pos2[1] = 0; + pos2[2] = j; + + GSGLPushMatrix(gl); + GSGLSetPosition(gl, pos2); + GSGLSetRotation(gl, rot); + GSGLTetrakis(gl, 0.5, col, col2); + GSGLPopMatrix(gl); + } + } + + GSGLSetColor(gl, col); + GSGLPolygon(gl, 4, v, NULL, n); } static void after_render(GSEngine self){ @@ -101,7 +130,7 @@ int main(int argc, char** argv){ GSClientSetSkybox(GSEngineGetClient(engine), GSTrue); - if((sound = GSSoundOpen(GSClientGetSoundEngine(GSEngineGetClient(engine)), "game:/df97.xm")) != NULL){ + if((sound = GSSoundOpen(GSClientGetSoundEngine(GSEngineGetClient(engine)), "game:/2nd_pm.xm")) != NULL){ GSSoundSetLoop(sound, 1); GSSoundStart(sound); } diff --git a/engine/data/shader/shadow.fs b/engine/data/shader/shadow.fs index 15a001e..c93f836 100644 --- a/engine/data/shader/shadow.fs +++ b/engine/data/shader/shadow.fs @@ -8,6 +8,7 @@ varying vec4 vColor; uniform sampler2D depth_texture; uniform sampler2D current_texture; uniform float enable_lighting; +uniform float enable_texture; vec4 PhongShading(void) { @@ -67,8 +68,9 @@ void main(void){ vec4 ambient = gl_LightSource[0].ambient; float shadow_coef = ShadowCoef(); - c = c * texture2D(current_texture, gl_TexCoord[0].st); + if(enable_texture >= 0.5){ + c = c * texture2D(current_texture, gl_TexCoord[0].st); + } gl_FragColor = ambient * shadow_coef * c + (1.0 - ambient) * c; - gl_FragColor.a = 1.0; } diff --git a/engine/include/GearSrc/GL.h b/engine/include/GearSrc/GL.h index 53bd12d..2a54cef 100644 --- a/engine/include/GearSrc/GL.h +++ b/engine/include/GearSrc/GL.h @@ -32,6 +32,7 @@ GSDECL void GSGLTextEx(GSGL gl, GSNumber x, GSNumber y, const char* text, GSNu GSDECL void GSGLText(GSGL gl, GSNumber x, GSNumber y, const char* text); GSDECL double GSGLTextWidth(GSGL gl, const char* text); GSDECL double GSGLTextHeight(GSGL gl, const char* text); +GSDECL void GSGLTetrakis(GSGL gl, GSNumber scale, GSVector4 col1, GSVector4 col2); /* gl_shadow.c */ GSDECL void GSGLShadowInit(GSGL gl); diff --git a/engine/src/client.c b/engine/src/client.c index f80d5b1..8aaa90d 100644 --- a/engine/src/client.c +++ b/engine/src/client.c @@ -96,8 +96,14 @@ void GSClientDestroy(GSClient client) { free(client); } +static GSVector4 white = {1, 1, 1, 1}; + static void scene(GSClient client) { + GSGLSetColor(client->gl, white); + if(client->engine->param->render != NULL) client->engine->param->render(client->engine); + + GSGLSetColor(client->gl, white); } void GSClientStep(GSClient client) { @@ -107,7 +113,6 @@ void GSClientStep(GSClient client) { char buf[512]; char buf2[512]; GSVersion ver; - GSVector4 white = {1, 1, 1, 1}; GSVector4 yellow = {1, 1, 0, 1}; GSVector4 half = {0, 0, 0, 0.5}; GSVector2 sq[4]; @@ -116,7 +121,6 @@ void GSClientStep(GSClient client) { GSGLClear(client->gl); GSGLCameraSetup(client->gl); GSGLSetLight(client->gl); - GSGLSetColor(client->gl, white); GSGLTextBold(client->gl, 0); diff --git a/engine/src/gl/gl.c b/engine/src/gl/gl.c index 14e6e73..42635d3 100644 --- a/engine/src/gl/gl.c +++ b/engine/src/gl/gl.c @@ -116,7 +116,7 @@ void GSGLEnd2D(GSGL gl) { } void GSGLSetPosition(GSGL gl, GSVector3 pos) { - glTranslatef(pos[0], pos[1], pos[2]); + glTranslatef(pos[0], pos[1], -pos[2]); } void GSGLSetRotation(GSGL gl, GSVector3 rot) { diff --git a/engine/src/gl/gl_common.c b/engine/src/gl/gl_common.c index df86d48..7168dc7 100644 --- a/engine/src/gl/gl_common.c +++ b/engine/src/gl/gl_common.c @@ -172,3 +172,44 @@ void GSGLTexturePrepareEx(GSGL gl, GLuint* texture, unsigned char* rgba, int wid void GSGLTexturePrepare(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height) { GSGLTexturePrepareEx(gl, texture, rgba, width, height, 1); } + +/* who even uses this other than second reality? :) */ +void GSGLTetrakis(GSGL gl, GSNumber scale, GSVector4 col1, GSVector4 col2) { + GSVector3 v[] = { + {0, 1, 0}, + {-0.75, 0.75, -0.75}, + {0.75, 0.75, -0.75}}; + GSVector3 n; + GSVector3 rot2 = {0, 90, 0}; + GSVector3 rot3 = {0, 0, 90}; + GSVector3 rot4 = {90, 0, 0}; + int i, j, k = 0; + + for(i = 0; i < 3; i++) { + for(j = 0; j < 3; j++) v[i][j] *= scale; + } + + GSMathNormal3x3(n, v[0], v[1], v[2]); + + GSGLPushMatrix(gl); + for(i = 0; i < 6; i++) { + for(j = 0; j < 4; j++) { + GSGLSetColor(gl, ((k + j) % 2) ? col2 : col1); + GSGLPolygon(gl, 3, v, NULL, n); + + GSGLSetRotation(gl, rot2); + } + + if(i == 3) { + GSGLSetRotation(gl, rot4); + k++; + } else if(i == 4) { + GSGLSetRotation(gl, rot4); + GSGLSetRotation(gl, rot4); + } else { + GSGLSetRotation(gl, rot3); + k++; + } + } + GSGLPopMatrix(gl); +} diff --git a/engine/src/gl/gl_shadow.c b/engine/src/gl/gl_shadow.c index 6b25923..f85a051 100644 --- a/engine/src/gl/gl_shadow.c +++ b/engine/src/gl/gl_shadow.c @@ -30,6 +30,7 @@ void GSGLShadowInit(GSGL gl) { glUniform1i(glGetUniformLocation(gl->shadow_shader, "depth_texture"), 7); glUniform1i(glGetUniformLocation(gl->shadow_shader, "current_texture"), 0); glUniform1f(glGetUniformLocation(gl->shadow_shader, "enable_lighting"), 1); + glUniform1f(glGetUniformLocation(gl->shadow_shader, "enable_texture"), 0); glUseProgram(0); gl->shadow_use_shader = 1; diff --git a/engine/src/gl/gl_texture.c b/engine/src/gl/gl_texture.c index e84d542..ed844f1 100644 --- a/engine/src/gl/gl_texture.c +++ b/engine/src/gl/gl_texture.c @@ -23,8 +23,16 @@ void GSGLTextureSet(GSGL gl, GLuint texture) { glBindTexture(GL_TEXTURE_2D, texture); if(texture == 0) { glDisable(GL_TEXTURE_2D); + + if(gl->shadow_use_shader) { + glUniform1f(glGetUniformLocation(gl->shadow_shader, "enable_texture"), 0); + } } else { glEnable(GL_TEXTURE_2D); + + if(gl->shadow_use_shader) { + glUniform1f(glGetUniformLocation(gl->shadow_shader, "enable_texture"), 1); + } } }