aa
This commit is contained in:
parent
2a804556db
commit
08ea9a0e7b
7 changed files with 40 additions and 14 deletions
|
|
@ -10,9 +10,9 @@ GBClient GBClientCreate(GBEngine engine) {
|
|||
|
||||
client->engine = engine;
|
||||
|
||||
client->camera[0] = 0;
|
||||
client->camera[0] = 2;
|
||||
client->camera[1] = 1.5;
|
||||
client->camera[2] = 0;
|
||||
client->camera[2] = 2;
|
||||
|
||||
client->look_at[0] = 0;
|
||||
client->look_at[1] = 0;
|
||||
|
|
@ -21,7 +21,7 @@ GBClient GBClientCreate(GBEngine engine) {
|
|||
client->light0[0] = 5;
|
||||
client->light0[1] = 5;
|
||||
client->light0[2] = 5;
|
||||
client->light0[3] = 0;
|
||||
client->light0[3] = 1;
|
||||
|
||||
client->gl = GBGLCreate(client);
|
||||
|
||||
|
|
@ -114,9 +114,10 @@ void GBClientStep(GBClient client) {
|
|||
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, f);
|
||||
|
||||
GBGLShadowBeforeMapping(client->gl);
|
||||
scene();
|
||||
GBGLShadowAfterMapping(client->gl);
|
||||
if(GBGLShadowBeforeMapping(client->gl)) {
|
||||
scene();
|
||||
GBGLShadowAfterMapping(client->gl);
|
||||
}
|
||||
scene();
|
||||
GBGLShadowEnd(client->gl);
|
||||
|
||||
|
|
@ -127,8 +128,8 @@ void GBClientStep(GBClient client) {
|
|||
client->camera[0] = cos(r) * 2;
|
||||
client->camera[2] = sin(r) * 2;
|
||||
|
||||
// client->light0[0] = -cos(r) * 2;
|
||||
// client->light0[2] = -sin(r) * 2;
|
||||
client->light0[0] = -cos(r) * 5;
|
||||
client->light0[2] = -sin(r) * 5;
|
||||
|
||||
r += 0.1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ GBGL GBGLCreate(GBClient client) {
|
|||
}
|
||||
|
||||
void GBGLDestroy(GBGL gl) {
|
||||
GBGLShadowDeinit(gl);
|
||||
|
||||
free(gl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#define SHADOW_WIDTH 1024
|
||||
#define SHADOW_HEIGHT 1024
|
||||
#define SHADOW_CULL
|
||||
|
||||
void GBGLShadowInit(GBGL gl) {
|
||||
glGenTextures(1, &gl->shadow_texture);
|
||||
|
|
@ -29,12 +30,20 @@ void GBGLShadowInit(GBGL gl) {
|
|||
glUniform1i(glGetUniformLocation(gl->shadow_shader, "depth_texture"), 7);
|
||||
glUniform1i(glGetUniformLocation(gl->shadow_shader, "current_texture"), 0);
|
||||
glUseProgram(0);
|
||||
|
||||
gl->shadow_use_shader = 1;
|
||||
} else {
|
||||
glDeleteTextures(1, &gl->shadow_texture);
|
||||
|
||||
gl->shadow_use_shader = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void GBGLShadowBeforeMapping(GBGL gl) {
|
||||
int GBGLShadowBeforeMapping(GBGL gl) {
|
||||
GBVector3 zero = {0, 0, 0};
|
||||
|
||||
if(!gl->shadow_use_shader) return 0;
|
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
|
||||
|
|
@ -65,6 +74,8 @@ void GBGLShadowBeforeMapping(GBGL gl) {
|
|||
|
||||
glPolygonOffset(1.1f, 4.0f);
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void GBGLShadowAfterMapping(GBGL gl) {
|
||||
|
|
@ -125,6 +136,8 @@ void GBGLShadowAfterMapping(GBGL gl) {
|
|||
}
|
||||
|
||||
void GBGLShadowEnd(GBGL gl) {
|
||||
if(!gl->shadow_use_shader) return;
|
||||
|
||||
glUseProgram(0);
|
||||
|
||||
glActiveTexture(GL_TEXTURE7);
|
||||
|
|
@ -139,3 +152,10 @@ void GBGLShadowEnd(GBGL gl) {
|
|||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
void GBGLShadowDeinit(GBGL gl) {
|
||||
if(gl->shadow_use_shader) {
|
||||
glDeleteTextures(1, &gl->shadow_texture);
|
||||
glDeleteProgram(gl->shadow_shader);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue