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");
|
meditex_blue = LoadTexture("medib.tex");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lightmap = LoadTexture("lightmap.tex");
|
lightmap = LoadTexture("lightmap.tex");
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 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;
|
int nLights = 0;
|
||||||
LIGHT *lights;
|
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) {
|
void SetAmbient(COLOR c) {
|
||||||
ambient = c;
|
ambient = c;
|
||||||
|
|
||||||
UpdateAmbient();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddLight(LIGHT light) {
|
void AddLight(LIGHT light) {
|
||||||
|
@ -27,8 +21,6 @@ void AddLight(LIGHT light) {
|
||||||
|
|
||||||
lights[nLights] = light;
|
lights[nLights] = light;
|
||||||
nLights++;
|
nLights++;
|
||||||
|
|
||||||
UpdateAmbient();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetLights() {
|
void ResetLights() {
|
||||||
|
@ -38,8 +30,3 @@ void ResetLights() {
|
||||||
UpdateAmbient();
|
UpdateAmbient();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyLightScale() {
|
|
||||||
glAccum(GL_LOAD, 1);
|
|
||||||
glAccum(GL_RETURN, nLights+1);
|
|
||||||
}
|
|
||||||
|
|
57
render.c
57
render.c
|
@ -13,6 +13,7 @@ extern LEVEL level;
|
||||||
extern GLuint sphere;
|
extern GLuint sphere;
|
||||||
extern int nLights;
|
extern int nLights;
|
||||||
extern LIGHT *lights;
|
extern LIGHT *lights;
|
||||||
|
extern COLOR ambient;
|
||||||
extern GLuint lightmap;
|
extern GLuint lightmap;
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,38 +48,49 @@ void Render() {
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
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);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
glTexCoord2f(0.0, 0.0);
|
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);
|
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]);
|
glVertex3fv((GLfloat*)&room->polygons[i].vertices[0]);
|
||||||
|
glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[1]);
|
||||||
glVertex3fv((GLfloat*)&room->polygons[i].vertices[1]);
|
glVertex3fv((GLfloat*)&room->polygons[i].vertices[1]);
|
||||||
|
glMultiTexCoord2fv(0, (GLfloat*)&room->polygons[i].texcoords[2]);
|
||||||
glVertex3fv((GLfloat*)&room->polygons[i].vertices[2]);
|
glVertex3fv((GLfloat*)&room->polygons[i].vertices[2]);
|
||||||
}
|
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
glDepthFunc(GL_EQUAL);
|
glDepthFunc(GL_EQUAL);
|
||||||
glDepthMask(GL_FALSE);
|
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);
|
glBindTexture(GL_TEXTURE_2D, lightmap);
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
for(i = 0; i < nLights; i++) {
|
for(i = 0; i < nLights; i++) {
|
||||||
|
for(j = 0; j < room->nPolygons; j++) {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, room->polygons[j].texture);
|
||||||
|
|
||||||
glBegin(GL_TRIANGLES);
|
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));
|
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));
|
c = VectorMul(lights[i].diffuse, 1.0/((nLights+1)*d*d));
|
||||||
glColor3fv((GLfloat*)&c);
|
glColor3fv((GLfloat*)&c);
|
||||||
|
|
||||||
|
@ -90,36 +102,19 @@ void Render() {
|
||||||
for(k = 0; k < 3; k++) {
|
for(k = 0; k < 3; k++) {
|
||||||
v = VectorSub(room->polygons[j].vertices[k], p);
|
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]);
|
glVertex3fv((GLfloat*)&room->polygons[j].vertices[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
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);
|
free(room);
|
||||||
|
|
||||||
ApplyLightScale();
|
//ApplyLightScale();
|
||||||
|
|
||||||
/*glPushMatrix();
|
/*glPushMatrix();
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
|
@ -18,6 +18,5 @@ typedef struct _LIGHT {
|
||||||
void SetAmbient(COLOR);
|
void SetAmbient(COLOR);
|
||||||
void AddLight(LIGHT);
|
void AddLight(LIGHT);
|
||||||
void ResetLights();
|
void ResetLights();
|
||||||
void ApplyLightScale();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Reference in a new issue