Render-Qualitaet durch neue Render()-Funktion erhoeht.

This commit is contained in:
neoraider 2006-11-19 22:03:05 +00:00
parent e43bceafab
commit 16fd248bab
4 changed files with 53 additions and 74 deletions

2
init.c
View file

@ -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
View file

@ -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);
}

View file

@ -13,6 +13,7 @@ extern LEVEL level;
extern GLuint sphere;
extern int nLights;
extern LIGHT *lights;
extern COLOR ambient;
extern GLuint lightmap;
@ -47,38 +48,49 @@ 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);
glActiveTexture(GL_TEXTURE1);
glDisable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
for(i = 0; i < room->nPolygons; i++) {
glBindTexture(GL_TEXTURE_2D, room->polygons[i].texture);
glBegin(GL_TRIANGLES);
for(i = 0; i < room->nPolygons; i++) {
glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[0]);
glVertex3fv((GLfloat*)&room->polygons[i].vertices[0]);
glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[1]);
glVertex3fv((GLfloat*)&room->polygons[i].vertices[1]);
glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[2]);
glVertex3fv((GLfloat*)&room->polygons[i].vertices[2]);
}
glEnd();
}
glDepthFunc(GL_EQUAL);
glDepthMask(GL_FALSE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
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);
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;
if(d < 0) {
c = VectorMul(lights[i].diffuse, 1.0/((nLights+1)*d*d));
glColor3fv((GLfloat*)&c);
@ -90,36 +102,19 @@ void Render() {
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);
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();
}
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]);
glVertex3fv((GLfloat*)&room->polygons[i].vertices[0]);
glTexCoord2fv((GLfloat*)&room->polygons[i].texcoords[1]);
glVertex3fv((GLfloat*)&room->polygons[i].vertices[1]);
glTexCoord2fv((GLfloat*)&room->polygons[i].texcoords[2]);
glVertex3fv((GLfloat*)&room->polygons[i].vertices[2]);
glEnd();
}*/
}
free(room);
ApplyLightScale();
//ApplyLightScale();
/*glPushMatrix();
glDisable(GL_TEXTURE_2D);

View file

@ -18,6 +18,5 @@ typedef struct _LIGHT {
void SetAmbient(COLOR);
void AddLight(LIGHT);
void ResetLights();
void ApplyLightScale();
#endif