@@ -22,8 +22,6 @@ LightDrawer::LightDrawer()
2222{
2323 texture = 0 ;
2424 global_color = wxColor (50 , 50 , 50 , 255 );
25-
26- createGLTexture ();
2725}
2826
2927LightDrawer::~LightDrawer ()
@@ -35,18 +33,19 @@ LightDrawer::~LightDrawer()
3533
3634void LightDrawer::draw (int map_x, int map_y, int end_x, int end_y, int scroll_x, int scroll_y, bool fog)
3735{
36+ if (texture == 0 ) {
37+ createGLTexture ();
38+ }
39+
3840 int w = end_x - map_x;
3941 int h = end_y - map_y;
4042
4143 buffer.resize (static_cast <size_t >(w * h * PixelFormatRGBA));
4244
43- constexpr int half_tile_size = TileSize / 2 ;
4445 for (int x = 0 ; x < w; ++x) {
4546 for (int y = 0 ; y < h; ++y) {
4647 int mx = (map_x + x);
4748 int my = (map_y + y);
48- int px = (mx * TileSize + half_tile_size);
49- int py = (my * TileSize + half_tile_size);
5049 int index = (y * w + x);
5150 int color_index = index * PixelFormatRGBA;
5251
@@ -77,6 +76,7 @@ void LightDrawer::draw(int map_x, int map_y, int end_x, int end_y, int scroll_x,
7776 int draw_height = h * TileSize;
7877
7978 glBindTexture (GL_TEXTURE_2D, texture);
79+
8080 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
8181 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
8282 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 0x812F );
@@ -87,6 +87,7 @@ void LightDrawer::draw(int map_x, int map_y, int end_x, int end_y, int scroll_x,
8787 glBlendFunc (GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
8888 }
8989
90+ glColor4ub (255 , 255 , 255 , 255 ); // reset color
9091 glEnable (GL_TEXTURE_2D);
9192 glBegin (GL_QUADS);
9293 glTexCoord2f (0 .f , 0 .f ); glVertex2f (draw_x, draw_y);
@@ -141,9 +142,12 @@ void LightDrawer::clear() noexcept
141142void LightDrawer::createGLTexture ()
142143{
143144 glGenTextures (1 , &texture);
145+ ASSERT (texture == 0 );
144146}
145147
146148void LightDrawer::unloadGLTexture ()
147149{
148- glDeleteTextures (1 , &texture);
150+ if (texture != 0 ) {
151+ glDeleteTextures (1 , &texture);
152+ }
149153}
0 commit comments