2010-11-08, 08:58
Ok for those that want screen saver
this function was total mess. First coordinates are not scaled to final screen so Z axis is smth very random an screen saver appear as shaded (notice) blue trapezoid. Why blue, because parameters supplied for color were float array casted to byte (that will never gone work). One more thing the shader parameter is SM_TEXTURE so final color is never used and on screen appear what - last used texture which is some random text. It must be SM_DEFAULT. To work this you must put at beginning of file
Somth annoying once started screen saver there is constant check in
so you must put at start of the function
last one is my personal preference. better place is before call of the function to avoid some stack operations.
Code:
void CGUITextureGLES::DrawQuad(const CRect &rect, color_t color, CBaseTexture *texture, const CRect *texCoords)
{
if (texture)
{
glActiveTexture(GL_TEXTURE0);
texture->LoadToGPU();
glBindTexture(GL_TEXTURE_2D, texture->GetTextureObject());
glEnable(GL_TEXTURE_2D);
}
else
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); // Turn Blending On
VerifyGLState();
GLubyte col[4][4];
GLfloat ver[4][3];
GLfloat tex[4][2];
GLubyte idx[4] = {0, 1, 3, 2}; //determines order of triangle strip
if (texture)
g_Windowing.EnableGUIShader(SM_TEXTURE);
else
g_Windowing.EnableGUIShader(SM_DEFAULT);
GLint posLoc = g_Windowing.GUIShaderGetPos();
GLint colLoc = g_Windowing.GUIShaderGetCol();
GLint tex0Loc = g_Windowing.GUIShaderGetCoord0();
glVertexAttribPointer(posLoc, 3, GL_FLOAT, 0, 0, ver);
glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, col);
if (texture)
glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex);
glEnableVertexAttribArray(posLoc);
if (texture)
glEnableVertexAttribArray(tex0Loc);
glEnableVertexAttribArray(colLoc);
for (int i=0; i<4; i++)
{
// Setup Colour Values
col[i][0] = (GLubyte)GET_R(color);
col[i][1] = (GLubyte)GET_G(color);
col[i][2] = (GLubyte)GET_B(color);
col[i][3] = (GLubyte)GET_A(color);
}
// Setup vertex position values
// ver[0][3] = ver[1][3] = ver[2][3] = ver[3][3] = 0.0f; // FIXME, ver has only 3 elements - this is not correct
// ver[0][0] = ver[3][0] = rect.x2;
// ver[0][1] = ver[1][1] = rect.y2;
// ver[1][0] = ver[2][0] = rect.x2;
// ver[2][1] = ver[3][1] = rect.y2;
#define ROUND_TO_PIXEL(x) (float)(MathUtils::round_int(x))
ver[0][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x1, rect.y1));
ver[0][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x1, rect.y1));
ver[0][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x1, rect.y1));
ver[1][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x2, rect.y1));
ver[1][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x2, rect.y1));
ver[1][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x2, rect.y1));
ver[2][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x2, rect.y2));
ver[2][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x2, rect.y2));
ver[2][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x2, rect.y2));
ver[3][0] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalXCoord(rect.x1, rect.y2));
ver[3][1] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalYCoord(rect.x1, rect.y2));
ver[3][2] = ROUND_TO_PIXEL(g_graphicsContext.ScaleFinalZCoord(rect.x1, rect.y2));
if (texture)
{
// Setup texture coordinates
CRect coords = texCoords ? *texCoords : CRect(0.0f, 0.0f, 1.0f, 1.0f);
tex[0][0] = tex[3][0] = coords.x1;
tex[0][1] = tex[1][1] = coords.y1;
tex[1][0] = tex[2][0] = coords.x2;
tex[2][1] = tex[3][1] = coords.y2;
}
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx);
glDisableVertexAttribArray(posLoc);
glDisableVertexAttribArray(colLoc);
if (texture)glDisableVertexAttribArray(tex0Loc);
g_Windowing.DisableGUIShader();
if (texture)
glDisable(GL_TEXTURE_2D);
}
this function was total mess. First coordinates are not scaled to final screen so Z axis is smth very random an screen saver appear as shaded (notice) blue trapezoid. Why blue, because parameters supplied for color were float array casted to byte (that will never gone work). One more thing the shader parameter is SM_TEXTURE so final color is never used and on screen appear what - last used texture which is some random text. It must be SM_DEFAULT. To work this you must put at beginning of file
Code:
#include "MathUtils.h"
#include "GraphicContext.h"
Somth annoying once started screen saver there is constant check in
Code:
void CApplication::RenderScreenSaver()
so you must put at start of the function
Code:
if (!m_bScreenSave && screenSaverFadeAmount == 0)
return;
last one is my personal preference. better place is before call of the function to avoid some stack operations.