2012-09-10 18:10:59 +00:00
|
|
|
#include "platform.h"
|
2013-05-13 19:53:28 +00:00
|
|
|
#include "Renderer.h"
|
2012-09-10 18:10:59 +00:00
|
|
|
#include GLHEADER
|
2012-08-29 18:53:53 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include "Font.h"
|
2012-09-04 16:45:16 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2013-01-04 23:31:51 +00:00
|
|
|
#include "Log.h"
|
2013-06-14 15:48:13 +00:00
|
|
|
#include <stack>
|
2012-08-29 18:53:53 +00:00
|
|
|
|
|
|
|
namespace Renderer {
|
2013-06-14 15:48:13 +00:00
|
|
|
std::stack<Rect> clipStack;
|
|
|
|
|
2012-10-17 18:21:56 +00:00
|
|
|
void setColor4bArray(GLubyte* array, unsigned int color)
|
2012-08-29 18:53:53 +00:00
|
|
|
{
|
2013-06-27 10:31:16 +00:00
|
|
|
array[0] = (color & 0xff000000) >> 24;
|
|
|
|
array[1] = (color & 0x00ff0000) >> 16;
|
|
|
|
array[2] = (color & 0x0000ff00) >> 8;
|
2012-10-17 18:21:56 +00:00
|
|
|
array[3] = (color & 0x000000ff);
|
2012-08-29 18:53:53 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 18:21:56 +00:00
|
|
|
void buildGLColorArray(GLubyte* ptr, unsigned int color, unsigned int vertCount)
|
2012-08-29 18:53:53 +00:00
|
|
|
{
|
2013-06-27 10:31:16 +00:00
|
|
|
//convert color from ???? to RGBA?
|
|
|
|
unsigned int colorRGBA;
|
|
|
|
setColor4bArray((GLubyte *)&colorRGBA, color);
|
|
|
|
//write color to unsigned int array
|
|
|
|
GLuint * uiPtr = (GLuint *)ptr;
|
2012-08-29 18:53:53 +00:00
|
|
|
for(unsigned int i = 0; i < vertCount; i++)
|
|
|
|
{
|
2013-06-27 10:31:16 +00:00
|
|
|
uiPtr[i] = colorRGBA;
|
2012-08-29 18:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 19:34:50 +00:00
|
|
|
void translatef(float x, float y)
|
|
|
|
{
|
|
|
|
glTranslatef(x, y, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void translate(Vector2i offset)
|
|
|
|
{
|
|
|
|
translatef((float)offset.x, (float)offset.y);
|
|
|
|
}
|
|
|
|
|
2013-06-14 15:48:13 +00:00
|
|
|
void pushClipRect(int x, int y, unsigned int w, unsigned int h)
|
2013-06-02 22:33:49 +00:00
|
|
|
{
|
2013-06-14 15:48:13 +00:00
|
|
|
Rect rect(x, y, w, h);
|
|
|
|
if(rect.size.x == 0)
|
|
|
|
rect.size.x = Renderer::getScreenWidth() - rect.pos.x;
|
|
|
|
if(rect.size.y == 0)
|
|
|
|
rect.size.y = Renderer::getScreenHeight() - rect.pos.y;
|
|
|
|
|
|
|
|
//glScissor starts at the bottom left of the window
|
|
|
|
//so (0, 0, 1, 1) is the bottom left pixel
|
|
|
|
//everything else uses y+ = down, so flip it to be consistent
|
|
|
|
rect.pos.y = Renderer::getScreenHeight() - rect.pos.y - rect.size.y;
|
|
|
|
|
|
|
|
clipStack.push(rect);
|
|
|
|
glScissor(rect.pos.x, rect.pos.y, rect.size.x, rect.size.y);
|
2013-06-02 22:33:49 +00:00
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
|
2013-06-14 15:48:13 +00:00
|
|
|
void pushClipRect(Vector2i pos, Vector2u size)
|
2013-06-02 22:33:49 +00:00
|
|
|
{
|
2013-06-14 15:48:13 +00:00
|
|
|
pushClipRect(pos.x, pos.y, size.x, size.y);
|
2013-06-02 22:33:49 +00:00
|
|
|
}
|
|
|
|
|
2013-06-14 15:48:13 +00:00
|
|
|
void popClipRect()
|
2013-06-02 22:33:49 +00:00
|
|
|
{
|
2013-06-14 15:48:13 +00:00
|
|
|
if(clipStack.empty())
|
|
|
|
{
|
|
|
|
LOG(LogError) << "Tried to popClipRect while the stack was empty!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
clipStack.pop();
|
|
|
|
if(clipStack.empty())
|
|
|
|
{
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
}else{
|
|
|
|
Rect top = clipStack.top();
|
|
|
|
glScissor(top.pos.x, top.pos.y, top.size.x, top.size.y);
|
|
|
|
}
|
2013-06-02 22:33:49 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 18:21:56 +00:00
|
|
|
void drawRect(int x, int y, int w, int h, unsigned int color)
|
2012-08-29 18:53:53 +00:00
|
|
|
{
|
2013-05-15 07:50:59 +00:00
|
|
|
#ifdef USE_OPENGL_ES
|
|
|
|
GLshort points[12];
|
|
|
|
#else
|
2013-05-13 19:53:28 +00:00
|
|
|
GLint points[12];
|
2013-05-15 07:50:59 +00:00
|
|
|
#endif
|
2012-08-29 18:53:53 +00:00
|
|
|
|
|
|
|
points[0] = x; points [1] = y;
|
|
|
|
points[2] = x; points[3] = y + h;
|
|
|
|
points[4] = x + w; points[5] = y;
|
|
|
|
|
|
|
|
points[6] = x + w; points[7] = y;
|
|
|
|
points[8] = x; points[9] = y + h;
|
|
|
|
points[10] = x + w; points[11] = y + h;
|
|
|
|
|
|
|
|
GLubyte colors[6*4];
|
2012-10-17 18:21:56 +00:00
|
|
|
buildGLColorArray(colors, color, 6);
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-10-17 18:32:01 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2012-08-29 18:53:53 +00:00
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
2012-10-17 18:32:01 +00:00
|
|
|
|
2013-05-15 07:50:59 +00:00
|
|
|
#ifdef USE_OPENGL_ES
|
|
|
|
glVertexPointer(2, GL_SHORT, 0, points);
|
|
|
|
#else
|
2013-05-13 19:53:28 +00:00
|
|
|
glVertexPointer(2, GL_INT, 0, points);
|
2013-05-15 07:50:59 +00:00
|
|
|
#endif
|
2012-08-29 18:53:53 +00:00
|
|
|
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
|
|
|
|
2012-10-17 18:32:01 +00:00
|
|
|
glDisableClientState(GL_BLEND);
|
2012-08-29 18:53:53 +00:00
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
2012-10-17 18:32:01 +00:00
|
|
|
glDisable(GL_COLOR_ARRAY);
|
2012-08-29 18:53:53 +00:00
|
|
|
}
|
|
|
|
};
|