Render-Qualitaet durch neue Render()-Funktion erhoeht.
This commit is contained in:
parent
e43bceafab
commit
16fd248bab
4 changed files with 53 additions and 74 deletions
2
init.c
2
init.c
|
@ -49,8 +49,6 @@ int InitGame() {
|
|||
|
||||
meditex_blue = LoadTexture("medib.tex");
|
||||
|
||||
|
||||
|
||||
lightmap = LoadTexture("lightmap.tex");
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
|
|
15
light.c
15
light.c
|
@ -6,17 +6,11 @@
|
|||
int nLights = 0;
|
||||
LIGHT *lights;
|
||||
|
||||
static COLOR ambient;
|
||||
COLOR ambient;
|
||||
|
||||
|
||||
static void UpdateAmbient() {
|
||||
glClearColor(ambient.r/(nLights+1), ambient.g/(nLights+1), ambient.b/(nLights+1), 1.0);
|
||||
}
|
||||
|
||||
void SetAmbient(COLOR c) {
|
||||
ambient = c;
|
||||
|
||||
UpdateAmbient();
|
||||
}
|
||||
|
||||
void AddLight(LIGHT light) {
|
||||
|
@ -27,8 +21,6 @@ void AddLight(LIGHT light) {
|
|||
|
||||
lights[nLights] = light;
|
||||
nLights++;
|
||||
|
||||
UpdateAmbient();
|
||||
}
|
||||
|
||||
void ResetLights() {
|
||||
|
@ -38,8 +30,3 @@ void ResetLights() {
|
|||
UpdateAmbient();
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyLightScale() {
|
||||
glAccum(GL_LOAD, 1);
|
||||
glAccum(GL_RETURN, nLights+1);
|
||||
}
|
||||
|
|
109
render.c
109
render.c
|
@ -13,6 +13,7 @@ extern LEVEL level;
|
|||
extern GLuint sphere;
|
||||
extern int nLights;
|
||||
extern LIGHT *lights;
|
||||
extern COLOR ambient;
|
||||
extern GLuint lightmap;
|
||||
|
||||
|
||||
|
@ -47,79 +48,73 @@ void Render() {
|
|||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glColor3fv((GLfloat*)&ambient);
|
||||
|
||||
glColor3f(0.0, 0.0, 0.0);
|
||||
glTexCoord2f(0.0, 0.0);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
for(i = 0; i < room->nPolygons; i++) {
|
||||
glVertex3fv((GLfloat*)&room->polygons[i].vertices[0]);
|
||||
glVertex3fv((GLfloat*)&room->polygons[i].vertices[1]);
|
||||
glVertex3fv((GLfloat*)&room->polygons[i].vertices[2]);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
|
||||
glDepthFunc(GL_EQUAL);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, lightmap);
|
||||
|
||||
for(i = 0; i < nLights; i++) {
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
for(j = 0; j < room->nPolygons; j++) {
|
||||
d = VectorDot(room->polygons[j].normal, VectorSub(room->polygons[j].vertices[0], lights[i].pos));
|
||||
|
||||
if(d >= 0) continue;
|
||||
|
||||
c = VectorMul(lights[i].diffuse, 1.0/((nLights+1)*d*d));
|
||||
glColor3fv((GLfloat*)&c);
|
||||
|
||||
p = VectorAdd(lights[i].pos, VectorMul(room->polygons[j].normal, d));
|
||||
|
||||
v1 = VectorNormalize(VectorSub(room->polygons[j].vertices[0], room->polygons[j].vertices[1]));
|
||||
v2 = VectorCross(v1, room->polygons[j].normal);
|
||||
|
||||
for(k = 0; k < 3; k++) {
|
||||
v = VectorSub(room->polygons[j].vertices[k], p);
|
||||
|
||||
glTexCoord2f(VectorDot(v, v1)*0.04 / d + 0.5, VectorDot(v, v2)*0.04 / d + 0.5);
|
||||
glVertex3fv((GLfloat*)&room->polygons[j].vertices[k]);
|
||||
}
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glBlendFunc(GL_DST_COLOR, GL_ZERO);
|
||||
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
|
||||
/*for(i = 0; i < room->nPolygons; i++) {
|
||||
glBindTexture(GL_TEXTURE_2D, room->polygons[i].texture);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
glTexCoord2fv((GLfloat*)&room->polygons[i].texcoords[0]);
|
||||
glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[0]);
|
||||
glVertex3fv((GLfloat*)&room->polygons[i].vertices[0]);
|
||||
glTexCoord2fv((GLfloat*)&room->polygons[i].texcoords[1]);
|
||||
glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[1]);
|
||||
glVertex3fv((GLfloat*)&room->polygons[i].vertices[1]);
|
||||
glTexCoord2fv((GLfloat*)&room->polygons[i].texcoords[2]);
|
||||
glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[2]);
|
||||
glVertex3fv((GLfloat*)&room->polygons[i].vertices[2]);
|
||||
|
||||
glEnd();
|
||||
}*/
|
||||
}
|
||||
|
||||
glDepthFunc(GL_EQUAL);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, lightmap);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
for(i = 0; i < nLights; i++) {
|
||||
for(j = 0; j < room->nPolygons; j++) {
|
||||
glBindTexture(GL_TEXTURE_2D, room->polygons[j].texture);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
d = VectorDot(room->polygons[j].normal, VectorSub(room->polygons[j].vertices[0], lights[i].pos));
|
||||
|
||||
if(d < 0) {
|
||||
c = VectorMul(lights[i].diffuse, 1.0/((nLights+1)*d*d));
|
||||
glColor3fv((GLfloat*)&c);
|
||||
|
||||
p = VectorAdd(lights[i].pos, VectorMul(room->polygons[j].normal, d));
|
||||
|
||||
v1 = VectorNormalize(VectorSub(room->polygons[j].vertices[0], room->polygons[j].vertices[1]));
|
||||
v2 = VectorCross(v1, room->polygons[j].normal);
|
||||
|
||||
for(k = 0; k < 3; k++) {
|
||||
v = VectorSub(room->polygons[j].vertices[k], p);
|
||||
|
||||
glMultiTexCoord2f(0, VectorDot(v, v1)*0.04 / d + 0.5, VectorDot(v, v2)*0.04 / d + 0.5);
|
||||
glMultiTexCoord2fv(1, (GLfloat*)&room->polygons[j].texcoords[k]);
|
||||
glVertex3fv((GLfloat*)&room->polygons[j].vertices[k]);
|
||||
}
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
free(room);
|
||||
|
||||
ApplyLightScale();
|
||||
//ApplyLightScale();
|
||||
|
||||
/*glPushMatrix();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
|
|
@ -18,6 +18,5 @@ typedef struct _LIGHT {
|
|||
void SetAmbient(COLOR);
|
||||
void AddLight(LIGHT);
|
||||
void ResetLights();
|
||||
void ApplyLightScale();
|
||||
|
||||
#endif
|
||||
|
|
Reference in a new issue