mirror of https://github.com/skeeto/pixelcity.git
Reduced sky render to single-pass, which also made clouds higher res and eliminated a texture. Also took a stab at clean up the unholy mess that is CTexture::Rebuild.
This commit is contained in:
parent
1e8027f1cd
commit
ea90760535
4
Sky.cpp
4
Sky.cpp
|
@ -82,10 +82,6 @@ void CSky::Render ()
|
|||
glEnable (GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, TextureId (TEXTURE_SKY));
|
||||
glCallList (m_list);
|
||||
glEnable (GL_BLEND);
|
||||
glBindTexture(GL_TEXTURE_2D, TextureId (TEXTURE_CLOUDS));
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glCallList (m_list);
|
||||
glPopMatrix ();
|
||||
glPopAttrib ();
|
||||
glDepthMask (true);
|
||||
|
|
266
Texture.cpp
266
Texture.cpp
|
@ -145,6 +145,8 @@ public:
|
|||
void Clear () { _ready = false; }
|
||||
void Rebuild ();
|
||||
void DrawWindows ();
|
||||
void DrawSky ();
|
||||
void DrawHeadlight ();
|
||||
};
|
||||
|
||||
static CTexture* head;
|
||||
|
@ -437,6 +439,127 @@ void CTexture::DrawWindows ()
|
|||
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
void CTexture::DrawSky ()
|
||||
{
|
||||
|
||||
GLrgba color;
|
||||
float grey;
|
||||
float scale, inv_scale;
|
||||
int i, x, y;
|
||||
int width, height;
|
||||
int offset;
|
||||
int width_adjust;
|
||||
int height_adjust;
|
||||
|
||||
color = WorldBloomColor ();
|
||||
grey = (color.red + color.green + color.blue) / 3.0f;
|
||||
//desaturate, slightly dim
|
||||
color = (color + glRgba (grey) * 2.0f) / 15.0f;
|
||||
glDisable (GL_BLEND);
|
||||
glBegin (GL_QUAD_STRIP);
|
||||
glColor3f (0,0,0);
|
||||
glVertex2i (0, _half);
|
||||
glVertex2i (_size, _half);
|
||||
glColor3fv (&color.red);
|
||||
glVertex2i (0, _size - 2);
|
||||
glVertex2i (_size, _size - 2);
|
||||
glEnd ();
|
||||
//Draw a bunch of little faux-buildings on the horizon.
|
||||
for (i = 0; i < _size; i += 5)
|
||||
drawrect (i, _size - RandomVal (8) - RandomVal (8) - RandomVal (8), i + RandomVal (9), _size, glRgba (0.0f));
|
||||
//Draw the clouds
|
||||
for (i = _size - 30; i > 5; i -= 2) {
|
||||
|
||||
x = RandomVal (_size);
|
||||
y = i;
|
||||
|
||||
scale = 1.0f - ((float)y / (float)_size);
|
||||
width = RandomVal (_half / 2) + (int)((float)_half * scale) / 2;
|
||||
scale = 1.0f - (float)y / (float)_size;
|
||||
height = (int)((float)(width) * scale);
|
||||
height = MAX (height, 4);
|
||||
|
||||
glEnable (GL_BLEND);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glBindTexture (GL_TEXTURE_2D, TextureId (TEXTURE_SOFT_CIRCLE));
|
||||
glDepthMask (false);
|
||||
glBegin (GL_QUADS);
|
||||
for (offset = -_size; offset <= _size; offset += _size) {
|
||||
for (scale = 1.0f; scale > 0.0f; scale -= 0.25f) {
|
||||
|
||||
inv_scale = 1.0f - (scale);
|
||||
if (scale < 0.4f)
|
||||
color = WorldBloomColor () * 0.1f;
|
||||
else
|
||||
color = glRgba (0.0f);
|
||||
color.alpha = 0.2f;
|
||||
glColor4fv (&color.red);
|
||||
width_adjust = (int)((float)width / 2.0f + (int)(inv_scale * ((float)width / 2.0f)));
|
||||
height_adjust = height + (int)(scale * (float)height * 0.99f);
|
||||
glTexCoord2f (0, 0); glVertex2i (offset + x - width_adjust, y + height - height_adjust);
|
||||
glTexCoord2f (0, 1); glVertex2i (offset + x - width_adjust, y + height);
|
||||
glTexCoord2f (1, 1); glVertex2i (offset + x + width_adjust, y + height);
|
||||
glTexCoord2f (1, 0); glVertex2i (offset + x + width_adjust, y + height - height_adjust);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
glEnd ();
|
||||
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
void CTexture::DrawHeadlight ()
|
||||
{
|
||||
|
||||
float radius;
|
||||
int i, x, y;
|
||||
GLvector2 pos;
|
||||
|
||||
//Make a simple circle of light, bright in the center and fading out
|
||||
radius = ((float)_half) - 20;
|
||||
x = _half - 20;
|
||||
y = _half;
|
||||
glEnable (GL_BLEND);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBegin (GL_TRIANGLE_FAN);
|
||||
glColor4f (0.8f, 0.8f, 0.8f, 0.6f);
|
||||
glVertex2i (_half - 5, y);
|
||||
glColor4f (0, 0, 0, 0);
|
||||
for (i = 0; i <= 360; i += 36) {
|
||||
pos.x = sinf ((float)(i % 360) * DEGREES_TO_RADIANS) * radius;
|
||||
pos.y = cosf ((float)(i % 360) * DEGREES_TO_RADIANS) * radius;
|
||||
glVertex2i (x + (int)pos.x, _half + (int)pos.y);
|
||||
}
|
||||
glEnd ();
|
||||
x = _half + 20;
|
||||
glBegin (GL_TRIANGLE_FAN);
|
||||
glColor4f (0.8f, 0.8f, 0.8f, 0.6f);
|
||||
glVertex2i (_half + 5, y);
|
||||
glColor4f (0, 0, 0, 0);
|
||||
for (i = 0; i <= 360; i += 36) {
|
||||
pos.x = sinf ((float)(i % 360) * DEGREES_TO_RADIANS) * radius;
|
||||
pos.y = cosf ((float)(i % 360) * DEGREES_TO_RADIANS) * radius;
|
||||
glVertex2i (x + (int)pos.x, _half + (int)pos.y);
|
||||
}
|
||||
glEnd ();
|
||||
x = _half - 6;
|
||||
drawrect_simple (x - 3, y - 2, x + 2, y + 2, glRgba (1.0f));
|
||||
x = _half + 6;
|
||||
drawrect_simple (x - 2, y - 2, x + 3, y + 2, glRgba (1.0f));
|
||||
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
|
||||
Here is where ALL of the procedural textures are created. It's filled with
|
||||
|
@ -454,9 +577,7 @@ void CTexture::Rebuild ()
|
|||
int name_num, prefix_num, suffix_num;
|
||||
int max_size;
|
||||
float radius;
|
||||
float grey;
|
||||
GLvector2 pos;
|
||||
GLrgba color;
|
||||
bool use_framebuffer;
|
||||
unsigned char* bits;
|
||||
unsigned start;
|
||||
|
@ -497,46 +618,6 @@ void CTexture::Rebuild ()
|
|||
use_framebuffer = true;
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
switch (_my_id) {
|
||||
case TEXTURE_GROUND:
|
||||
unsigned char icolor[4];
|
||||
char cell;
|
||||
|
||||
//memset (buffer, 0, 1024 * 1024 * 4);
|
||||
bits = new unsigned char[_size * _size * 4];
|
||||
ZeroMemory (bits, sizeof (bits));
|
||||
icolor[3] = 255;
|
||||
for (x = 0; x < _size; x++) {
|
||||
for (y = 0; y < _size; y++) {
|
||||
cell = WorldCell (x, y);
|
||||
memset (icolor, 0, 3);
|
||||
if (cell & CLAIM_ROAD)
|
||||
icolor[0] = icolor[1] = icolor[2] = 12;
|
||||
if (cell == CLAIM_WALK)
|
||||
icolor[0] = icolor[1] = icolor[2] = 64;
|
||||
icolor[0] += (unsigned char)RandomVal (4);
|
||||
icolor[1] += (unsigned char)RandomVal (4);
|
||||
icolor[2] += (unsigned char)RandomVal (4);
|
||||
if (1) { //use this to make the road lanes visible
|
||||
if (cell & MAP_ROAD_EAST)
|
||||
icolor[0] += 128;
|
||||
if (cell & MAP_ROAD_WEST)
|
||||
icolor[1] += 128;
|
||||
if (cell & MAP_ROAD_NORTH)
|
||||
icolor[2] += 128;
|
||||
if (cell & MAP_ROAD_SOUTH) {
|
||||
icolor[1] += 64;
|
||||
icolor[2] += 64;
|
||||
}
|
||||
}
|
||||
memcpy (&bits[(x + y * _size) * 4], &icolor[0], 4);
|
||||
}
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, _glid);
|
||||
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, _size, _size, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);
|
||||
use_framebuffer = false;
|
||||
delete bits;
|
||||
break;
|
||||
case TEXTURE_LATTICE:
|
||||
glLineWidth (2.0f);
|
||||
|
||||
|
@ -600,37 +681,7 @@ void CTexture::Rebuild ()
|
|||
}
|
||||
break;
|
||||
case TEXTURE_HEADLIGHT:
|
||||
//Make a simple circle of light, bright in the center and fading out
|
||||
radius = ((float)_half) - 20;
|
||||
x = _half - 20;
|
||||
y = _half;
|
||||
glEnable (GL_BLEND);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBegin (GL_TRIANGLE_FAN);
|
||||
glColor4f (0.8f, 0.8f, 0.8f, 0.6f);
|
||||
glVertex2i (_half - 5, y);
|
||||
glColor4f (0, 0, 0, 0);
|
||||
for (i = 0; i <= 360; i += 36) {
|
||||
pos.x = sinf ((float)(i % 360) * DEGREES_TO_RADIANS) * radius;
|
||||
pos.y = cosf ((float)(i % 360) * DEGREES_TO_RADIANS) * radius;
|
||||
glVertex2i (x + (int)pos.x, _half + (int)pos.y);
|
||||
}
|
||||
glEnd ();
|
||||
x = _half + 20;
|
||||
glBegin (GL_TRIANGLE_FAN);
|
||||
glColor4f (0.8f, 0.8f, 0.8f, 0.6f);
|
||||
glVertex2i (_half + 5, y);
|
||||
glColor4f (0, 0, 0, 0);
|
||||
for (i = 0; i <= 360; i += 36) {
|
||||
pos.x = sinf ((float)(i % 360) * DEGREES_TO_RADIANS) * radius;
|
||||
pos.y = cosf ((float)(i % 360) * DEGREES_TO_RADIANS) * radius;
|
||||
glVertex2i (x + (int)pos.x, _half + (int)pos.y);
|
||||
}
|
||||
glEnd ();
|
||||
x = _half - 6;
|
||||
drawrect_simple (x - 3, y - 2, x + 2, y + 2, glRgba (1.0f));
|
||||
x = _half + 6;
|
||||
drawrect_simple (x - 2, y - 2, x + 3, y + 2, glRgba (1.0f));
|
||||
DrawHeadlight ();
|
||||
break;
|
||||
case TEXTURE_LOGOS:
|
||||
i = 0;
|
||||
|
@ -652,55 +703,6 @@ void CTexture::Rebuild ()
|
|||
i += LOGO_PIXELS;
|
||||
}
|
||||
break;
|
||||
case TEXTURE_CLOUDS:
|
||||
int width, height;
|
||||
int offset;
|
||||
float scale;
|
||||
|
||||
for (i = _size - 30; i > 5; i -= 1) {
|
||||
x = RandomVal (_size);
|
||||
y = i;
|
||||
|
||||
scale = 1.0f - ((float)y / (float)_size);
|
||||
width = RandomVal (_half / 2) + (int)((float)_half * scale) / 2;
|
||||
scale = 1.0f - (float)y / (float)_size;
|
||||
height = (int)((float)(width) * scale);
|
||||
height = MAX (height, 4);
|
||||
|
||||
glEnable (GL_BLEND);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glBindTexture (GL_TEXTURE_2D, TextureId (TEXTURE_SOFT_CIRCLE));
|
||||
glDepthMask (false);
|
||||
glBegin (GL_QUADS);
|
||||
for (offset = -_size; offset <= _size; offset += _size) {
|
||||
for (scale = 1.0f; scale > 0.0f; scale -= 0.25f) {
|
||||
int width_adjust;
|
||||
int height_adjust;
|
||||
float inv_scale;
|
||||
|
||||
inv_scale = 1.0f - (scale);
|
||||
|
||||
if (scale < 0.4f)
|
||||
color = WorldBloomColor () * 0.1f;
|
||||
else
|
||||
color = glRgba (0.0f);
|
||||
color.alpha = 1.0f;
|
||||
glColor4fv (&color.red);
|
||||
width_adjust = (int)((float)width / 2.0f + (int)(inv_scale * ((float)width / 2.0f)));
|
||||
height_adjust = height + (int)(scale * (float)height * 0.99f);
|
||||
|
||||
glTexCoord2f (0, 0); glVertex2i (offset + x - width_adjust, y + height - height_adjust);
|
||||
glTexCoord2f (0, 1); glVertex2i (offset + x - width_adjust, y + height);
|
||||
glTexCoord2f (1, 1); glVertex2i (offset + x + width_adjust, y + height);
|
||||
glTexCoord2f (1, 0); glVertex2i (offset + x + width_adjust, y + height - height_adjust);
|
||||
}
|
||||
|
||||
}
|
||||
glEnd ();
|
||||
}
|
||||
break;
|
||||
case TEXTURE_TRIM:
|
||||
int margin;
|
||||
y = 0;
|
||||
|
@ -718,22 +720,7 @@ void CTexture::Rebuild ()
|
|||
drawrect_simple (x + margin, y + margin * 2, x + TRIM_PIXELS - margin, y + TRIM_PIXELS - margin, glRgba (1.0f), glRgba (0.5f));
|
||||
break;
|
||||
case TEXTURE_SKY:
|
||||
color = WorldBloomColor ();
|
||||
grey = (color.red + color.green + color.blue) / 3.0f;
|
||||
//desaturate, slightly dim
|
||||
color = (color + glRgba (grey) * 2.0f) / 15.0f;
|
||||
glDisable (GL_BLEND);
|
||||
glBegin (GL_QUAD_STRIP);
|
||||
glColor3f (0,0,0);
|
||||
glVertex2i (0, _half);
|
||||
glVertex2i (_size, _half);
|
||||
glColor3fv (&color.red);
|
||||
glVertex2i (0, _size - 2);
|
||||
glVertex2i (_size, _size - 2);
|
||||
glEnd ();
|
||||
//Draw a bunch of little faux-buildings on the horizon.
|
||||
for (i = 0; i < _size; i += 5)
|
||||
drawrect (i, _size - RandomVal (8) - RandomVal (8) - RandomVal (8), i + RandomVal (9), _size, glRgba (0.0f));
|
||||
DrawSky ();
|
||||
break;
|
||||
default: //building textures
|
||||
DrawWindows ();
|
||||
|
@ -872,14 +859,11 @@ void TextureInit (void)
|
|||
{
|
||||
|
||||
new CTexture (TEXTURE_SKY, 512, true, false, false);
|
||||
new CTexture (TEXTURE_CLOUDS, 256, true, false, true);
|
||||
new CTexture (TEXTURE_LATTICE, 128, true, true, true);
|
||||
new CTexture (TEXTURE_LIGHT, 128, false, false, true);
|
||||
new CTexture (TEXTURE_SOFT_CIRCLE, 128, false, false, true);
|
||||
new CTexture (TEXTURE_HEADLIGHT, 128, false, false, true);
|
||||
new CTexture (TEXTURE_TRIM, TRIM_RESOLUTION, true, false, false);
|
||||
if (SHOW_DEBUG_GROUND)
|
||||
new CTexture (TEXTURE_GROUND, 1024, false, false, false);
|
||||
new CTexture (TEXTURE_LOGOS, LOGO_RESOLUTION, true, false, true);
|
||||
for (int i = TEXTURE_BUILDING1; i <= TEXTURE_BUILDING9; i++)
|
||||
new CTexture (i, 512, true, false, false);
|
||||
|
|
|
@ -14,11 +14,9 @@
|
|||
|
||||
enum
|
||||
{
|
||||
TEXTURE_GROUND,
|
||||
TEXTURE_LIGHT,
|
||||
TEXTURE_SOFT_CIRCLE,
|
||||
TEXTURE_SKY,
|
||||
TEXTURE_CLOUDS,
|
||||
TEXTURE_LOGOS,
|
||||
TEXTURE_TRIM,
|
||||
TEXTURE_BLOOM,
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <gl\glaux.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
|
||||
#include "glTypes.h"
|
||||
#include "building.h"
|
||||
|
@ -39,6 +40,8 @@
|
|||
#include "win.h"
|
||||
#include "world.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct plot
|
||||
{
|
||||
int x;
|
||||
|
@ -407,7 +410,7 @@ static void do_reset (void)
|
|||
float west_street, north_street, east_street, south_street;
|
||||
|
||||
//Re-init Random to make the same city each time. Helpful when running tests.
|
||||
//RandomInit (6);
|
||||
RandomInit (6);
|
||||
reset_needed = false;
|
||||
broadway_done = false;
|
||||
skyscrapers = 0;
|
||||
|
@ -555,6 +558,7 @@ static void do_reset (void)
|
|||
if (x < WORLD_EDGE || x > WORLD_SIZE - WORLD_EDGE)
|
||||
x += 28;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -660,7 +664,7 @@ void WorldRender ()
|
|||
glDisable (GL_BLEND);
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glColor3f (1,1,1);
|
||||
glBindTexture (GL_TEXTURE_2D, TextureId (TEXTURE_GROUND));
|
||||
glBindTexture (GL_TEXTURE_2D, 0);
|
||||
glBegin (GL_QUADS);
|
||||
glTexCoord2f (0, 0); glVertex3f ( 0., 0, 0);
|
||||
glTexCoord2f (0, 1); glVertex3f ( 0, 0, 1024);
|
||||
|
|
Loading…
Reference in New Issue