#include "glutil.hpp"
#include "texture.hpp"
#include "texture_manager.hpp"
-#define LIGHTMAP_DIV 4
+#define LIGHTMAP_DIV 5
static inline int next_po2(int val)
{
const Vector& position, int layer)
{
draw_text(font, text, Vector(position.x + SCREEN_WIDTH/2, position.y),
- CENTER_ALLIGN, layer);
+ ALIGN_CENTER, layer);
}
void
*color = Color( 1.0f, 1.0f, 1.0f);
return;
}
+
DrawingRequest request;
request.type = GETLIGHT;
request.pos = transform.apply(position);
- request.layer = LAYER_GUI; //make sure all get_light requests are handled last.
+ //There is no light offscreen.
+ if(request.pos.x >= SCREEN_WIDTH || request.pos.y >= SCREEN_HEIGHT
+ || request.pos.x < 0 || request.pos.y < 0){
+ *color = Color( 0, 0, 0);
+ return;
+ }
+
+ request.layer = LAYER_GUI; //make sure all get_light requests are handled last.
GetLightRequest* getlightrequest = new GetLightRequest;
getlightrequest->color_ptr = color;
request.request_data = getlightrequest;
for( int i = 0; i<3; i++)
pixels[i] = 0.0f; //set to black
- //TODO: hacky. Make coordinate conversion more generic
- glReadPixels((GLint) request.pos.x / 4, 600-(GLint)request.pos.y / 4, 1, 1, GL_RGB, GL_FLOAT, pixels);
- *(getlightrequest->color_ptr) = Color( pixels[0], pixels[1], pixels[2]);
- //printf("get_light %f/%f r%f g%f b%f\n", request.pos.x, request.pos.y, pixels[0], pixels[1], pixels[2]);
+ float posX = request.pos.x * lightmap_width / SCREEN_WIDTH;
+ float posY = screen->h - request.pos.y * lightmap_height / SCREEN_HEIGHT;
+ glReadPixels((GLint) posX, (GLint) posY , 1, 1, GL_RGB, GL_FLOAT, pixels);
+ *(getlightrequest->color_ptr) = Color( pixels[0], pixels[1], pixels[2]);
+ //printf("get_light %f/%f =>%f/%f r%f g%f b%f\n", request.pos.x, request.pos.y, posX, posY, pixels[0], pixels[1], pixels[2]);
delete getlightrequest;
}
case SURFACE:
{
const Surface* surface = (const Surface*) i->request_data;
- if (i->angle == 0.0f &&
+ if (i->angle == 0.0f &&
i->color.red == 1.0f && i->color.green == 1.0f &&
i->color.blue == 1.0f && i->color.alpha == 1.0f )
surface->draw(i->pos.x, i->pos.y, i->alpha, i->drawing_effect);