Fixed rotate overlay drawing.

This commit is contained in:
leo 2015-05-25 18:02:57 +00:00
parent f001916a05
commit 6b86d13042
4 changed files with 129 additions and 117 deletions

View file

@ -146,10 +146,11 @@ void lcContext::CreateShaderPrograms()
// LC_PROGRAM_TEXTURE // LC_PROGRAM_TEXTURE
"#version 110\n" "#version 110\n"
"varying vec2 PixelTexCoord;\n" "varying vec2 PixelTexCoord;\n"
"uniform vec4 Color;\n"
"uniform sampler2D Texture;\n" "uniform sampler2D Texture;\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
" gl_FragColor = texture2D(Texture, PixelTexCoord);\n" " gl_FragColor = texture2D(Texture, PixelTexCoord) * Color;\n"
"}\n", "}\n",
// LC_PROGRAM_VERTEX_COLOR // LC_PROGRAM_VERTEX_COLOR
"#version 110\n" "#version 110\n"

View file

@ -61,58 +61,58 @@ extern PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC lcFramebufferRenderbufferEXT;
extern PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC lcGetFramebufferAttachmentParameterivEXT; extern PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC lcGetFramebufferAttachmentParameterivEXT;
extern PFNGLGENERATEMIPMAPEXTPROC lcGenerateMipmapEXT; extern PFNGLGENERATEMIPMAPEXTPROC lcGenerateMipmapEXT;
extern PFNGLATTACHSHADERPROC lcAttachShader; extern PFNGLATTACHSHADERPROC lcAttachShader;
extern PFNGLBINDATTRIBLOCATIONPROC lcBindAttribLocation; extern PFNGLBINDATTRIBLOCATIONPROC lcBindAttribLocation;
extern PFNGLCOMPILESHADERPROC lcCompileShader; extern PFNGLCOMPILESHADERPROC lcCompileShader;
extern PFNGLCREATEPROGRAMPROC lcCreateProgram; extern PFNGLCREATEPROGRAMPROC lcCreateProgram;
extern PFNGLCREATESHADERPROC lcCreateShader; extern PFNGLCREATESHADERPROC lcCreateShader;
extern PFNGLDELETEPROGRAMPROC lcDeleteProgram; extern PFNGLDELETEPROGRAMPROC lcDeleteProgram;
extern PFNGLDELETESHADERPROC lcDeleteShader; extern PFNGLDELETESHADERPROC lcDeleteShader;
extern PFNGLDETACHSHADERPROC lcDetachShader; extern PFNGLDETACHSHADERPROC lcDetachShader;
extern PFNGLDISABLEVERTEXATTRIBARRAYPROC lcDisableVertexAttribArray; extern PFNGLDISABLEVERTEXATTRIBARRAYPROC lcDisableVertexAttribArray;
extern PFNGLENABLEVERTEXATTRIBARRAYPROC lcEnableVertexAttribArray; extern PFNGLENABLEVERTEXATTRIBARRAYPROC lcEnableVertexAttribArray;
extern PFNGLGETACTIVEATTRIBPROC lcGetActiveAttrib; extern PFNGLGETACTIVEATTRIBPROC lcGetActiveAttrib;
extern PFNGLGETACTIVEUNIFORMPROC lcGetActiveUniform; extern PFNGLGETACTIVEUNIFORMPROC lcGetActiveUniform;
extern PFNGLGETATTACHEDSHADERSPROC lcGetAttachedShaders; extern PFNGLGETATTACHEDSHADERSPROC lcGetAttachedShaders;
extern PFNGLGETATTRIBLOCATIONPROC lcGetAttribLocation; extern PFNGLGETATTRIBLOCATIONPROC lcGetAttribLocation;
extern PFNGLGETPROGRAMIVPROC lcGetProgramiv; extern PFNGLGETPROGRAMIVPROC lcGetProgramiv;
extern PFNGLGETPROGRAMINFOLOGPROC lcGetProgramInfoLog; extern PFNGLGETPROGRAMINFOLOGPROC lcGetProgramInfoLog;
extern PFNGLGETSHADERIVPROC lcGetShaderiv; extern PFNGLGETSHADERIVPROC lcGetShaderiv;
extern PFNGLGETSHADERINFOLOGPROC lcGetShaderInfoLog; extern PFNGLGETSHADERINFOLOGPROC lcGetShaderInfoLog;
extern PFNGLGETSHADERSOURCEPROC lcGetShaderSource; extern PFNGLGETSHADERSOURCEPROC lcGetShaderSource;
extern PFNGLGETUNIFORMLOCATIONPROC lcGetUniformLocation; extern PFNGLGETUNIFORMLOCATIONPROC lcGetUniformLocation;
extern PFNGLGETUNIFORMFVPROC lcGetUniformfv; extern PFNGLGETUNIFORMFVPROC lcGetUniformfv;
extern PFNGLGETUNIFORMIVPROC lcGetUniformiv; extern PFNGLGETUNIFORMIVPROC lcGetUniformiv;
extern PFNGLGETVERTEXATTRIBDVPROC lcGetVertexAttribdv; extern PFNGLGETVERTEXATTRIBDVPROC lcGetVertexAttribdv;
extern PFNGLGETVERTEXATTRIBFVPROC lcGetVertexAttribfv; extern PFNGLGETVERTEXATTRIBFVPROC lcGetVertexAttribfv;
extern PFNGLGETVERTEXATTRIBIVPROC lcGetVertexAttribiv; extern PFNGLGETVERTEXATTRIBIVPROC lcGetVertexAttribiv;
extern PFNGLGETVERTEXATTRIBPOINTERVPROC lcGetVertexAttribPointerv; extern PFNGLGETVERTEXATTRIBPOINTERVPROC lcGetVertexAttribPointerv;
extern PFNGLISPROGRAMPROC lcIsProgram; extern PFNGLISPROGRAMPROC lcIsProgram;
extern PFNGLISSHADERPROC lcIsShader; extern PFNGLISSHADERPROC lcIsShader;
extern PFNGLLINKPROGRAMPROC lcLinkProgram; extern PFNGLLINKPROGRAMPROC lcLinkProgram;
extern PFNGLSHADERSOURCEPROC lcShaderSource; extern PFNGLSHADERSOURCEPROC lcShaderSource;
extern PFNGLUSEPROGRAMPROC lcUseProgram; extern PFNGLUSEPROGRAMPROC lcUseProgram;
extern PFNGLUNIFORM1FPROC lcUniform1f; extern PFNGLUNIFORM1FPROC lcUniform1f;
extern PFNGLUNIFORM2FPROC lcUniform2f; extern PFNGLUNIFORM2FPROC lcUniform2f;
extern PFNGLUNIFORM3FPROC lcUniform3f; extern PFNGLUNIFORM3FPROC lcUniform3f;
extern PFNGLUNIFORM4FPROC lcUniform4f; extern PFNGLUNIFORM4FPROC lcUniform4f;
extern PFNGLUNIFORM1IPROC lcUniform1i; extern PFNGLUNIFORM1IPROC lcUniform1i;
extern PFNGLUNIFORM2IPROC lcUniform2i; extern PFNGLUNIFORM2IPROC lcUniform2i;
extern PFNGLUNIFORM3IPROC lcUniform3i; extern PFNGLUNIFORM3IPROC lcUniform3i;
extern PFNGLUNIFORM4IPROC lcUniform4i; extern PFNGLUNIFORM4IPROC lcUniform4i;
extern PFNGLUNIFORM1FVPROC lcUniform1fv; extern PFNGLUNIFORM1FVPROC lcUniform1fv;
extern PFNGLUNIFORM2FVPROC lcUniform2fv; extern PFNGLUNIFORM2FVPROC lcUniform2fv;
extern PFNGLUNIFORM3FVPROC lcUniform3fv; extern PFNGLUNIFORM3FVPROC lcUniform3fv;
extern PFNGLUNIFORM4FVPROC lcUniform4fv; extern PFNGLUNIFORM4FVPROC lcUniform4fv;
extern PFNGLUNIFORM1IVPROC lcUniform1iv; extern PFNGLUNIFORM1IVPROC lcUniform1iv;
extern PFNGLUNIFORM2IVPROC lcUniform2iv; extern PFNGLUNIFORM2IVPROC lcUniform2iv;
extern PFNGLUNIFORM3IVPROC lcUniform3iv; extern PFNGLUNIFORM3IVPROC lcUniform3iv;
extern PFNGLUNIFORM4IVPROC lcUniform4iv; extern PFNGLUNIFORM4IVPROC lcUniform4iv;
extern PFNGLUNIFORMMATRIX2FVPROC lcUniformMatrix2fv; extern PFNGLUNIFORMMATRIX2FVPROC lcUniformMatrix2fv;
extern PFNGLUNIFORMMATRIX3FVPROC lcUniformMatrix3fv; extern PFNGLUNIFORMMATRIX3FVPROC lcUniformMatrix3fv;
extern PFNGLUNIFORMMATRIX4FVPROC lcUniformMatrix4fv; extern PFNGLUNIFORMMATRIX4FVPROC lcUniformMatrix4fv;
extern PFNGLVALIDATEPROGRAMPROC lcValidateProgram; extern PFNGLVALIDATEPROGRAMPROC lcValidateProgram;
extern PFNGLVERTEXATTRIBPOINTERPROC lcVertexAttribPointer; extern PFNGLVERTEXATTRIBPOINTERPROC lcVertexAttribPointer;
#define glBindBuffer lcBindBufferARB #define glBindBuffer lcBindBufferARB
#define glDeleteBuffers lcDeleteBuffersARB #define glDeleteBuffers lcDeleteBuffersARB
@ -165,57 +165,57 @@ extern PFNGLVERTEXATTRIBPOINTERPROC lcVertexAttribPointer;
#define glGetFramebufferAttachmentParameterivEXT lcGetFramebufferAttachmentParameterivEXT #define glGetFramebufferAttachmentParameterivEXT lcGetFramebufferAttachmentParameterivEXT
#define glGenerateMipmapEXT lcGenerateMipmapEXT #define glGenerateMipmapEXT lcGenerateMipmapEXT
#define glAttachShader lcAttachShader #define glAttachShader lcAttachShader
#define glBindAttribLocation lcBindAttribLocation #define glBindAttribLocation lcBindAttribLocation
#define glCompileShader lcCompileShader #define glCompileShader lcCompileShader
#define glCreateProgram lcCreateProgram #define glCreateProgram lcCreateProgram
#define glCreateShader lcCreateShader #define glCreateShader lcCreateShader
#define glDeleteProgram lcDeleteProgram #define glDeleteProgram lcDeleteProgram
#define glDeleteShader lcDeleteShader #define glDeleteShader lcDeleteShader
#define glDetachShader lcDetachShader #define glDetachShader lcDetachShader
#define glDisableVertexAttribArray lcDisableVertexAttribArray #define glDisableVertexAttribArray lcDisableVertexAttribArray
#define glEnableVertexAttribArray lcEnableVertexAttribArray #define glEnableVertexAttribArray lcEnableVertexAttribArray
#define glGetActiveAttrib lcGetActiveAttrib #define glGetActiveAttrib lcGetActiveAttrib
#define glGetActiveUniform lcGetActiveUniform #define glGetActiveUniform lcGetActiveUniform
#define glGetAttachedShaders lcGetAttachedShaders #define glGetAttachedShaders lcGetAttachedShaders
#define glGetAttribLocation lcGetAttribLocation #define glGetAttribLocation lcGetAttribLocation
#define glGetProgramiv lcGetProgramiv #define glGetProgramiv lcGetProgramiv
#define glGetProgramInfoLog lcGetProgramInfoLog #define glGetProgramInfoLog lcGetProgramInfoLog
#define glGetShaderiv lcGetShaderiv #define glGetShaderiv lcGetShaderiv
#define glGetShaderInfoLog lcGetShaderInfoLog #define glGetShaderInfoLog lcGetShaderInfoLog
#define glGetShaderSource lcGetShaderSource #define glGetShaderSource lcGetShaderSource
#define glGetUniformLocation lcGetUniformLocation #define glGetUniformLocation lcGetUniformLocation
#define glGetUniformfv lcGetUniformfv #define glGetUniformfv lcGetUniformfv
#define glGetUniformiv lcGetUniformiv #define glGetUniformiv lcGetUniformiv
#define glGetVertexAttribdv lcGetVertexAttribdv #define glGetVertexAttribdv lcGetVertexAttribdv
#define glGetVertexAttribfv lcGetVertexAttribfv #define glGetVertexAttribfv lcGetVertexAttribfv
#define glGetVertexAttribiv lcGetVertexAttribiv #define glGetVertexAttribiv lcGetVertexAttribiv
#define glGetVertexAttribPointerv lcGetVertexAttribPointerv #define glGetVertexAttribPointerv lcGetVertexAttribPointerv
#define glIsProgram lcIsProgram #define glIsProgram lcIsProgram
#define glIsShader lcIsShader #define glIsShader lcIsShader
#define glLinkProgram lcLinkProgram #define glLinkProgram lcLinkProgram
#define glShaderSource lcShaderSource #define glShaderSource lcShaderSource
#define glUseProgram lcUseProgram #define glUseProgram lcUseProgram
#define glUniform1f lcUniform1f #define glUniform1f lcUniform1f
#define glUniform2f lcUniform2f #define glUniform2f lcUniform2f
#define glUniform3f lcUniform3f #define glUniform3f lcUniform3f
#define glUniform4f lcUniform4f #define glUniform4f lcUniform4f
#define glUniform1i lcUniform1i #define glUniform1i lcUniform1i
#define glUniform2i lcUniform2i #define glUniform2i lcUniform2i
#define glUniform3i lcUniform3i #define glUniform3i lcUniform3i
#define glUniform4i lcUniform4i #define glUniform4i lcUniform4i
#define glUniform1fv lcUniform1fv #define glUniform1fv lcUniform1fv
#define glUniform2fv lcUniform2fv #define glUniform2fv lcUniform2fv
#define glUniform3fv lcUniform3fv #define glUniform3fv lcUniform3fv
#define glUniform4fv lcUniform4fv #define glUniform4fv lcUniform4fv
#define glUniform1iv lcUniform1iv #define glUniform1iv lcUniform1iv
#define glUniform2iv lcUniform2iv #define glUniform2iv lcUniform2iv
#define glUniform3iv lcUniform3iv #define glUniform3iv lcUniform3iv
#define glUniform4iv lcUniform4iv #define glUniform4iv lcUniform4iv
#define glUniformMatrix2fv lcUniformMatrix2fv #define glUniformMatrix2fv lcUniformMatrix2fv
#define glUniformMatrix3fv lcUniformMatrix3fv #define glUniformMatrix3fv lcUniformMatrix3fv
#define glUniformMatrix4fv lcUniformMatrix4fv #define glUniformMatrix4fv lcUniformMatrix4fv
#define glValidateProgram lcValidateProgram #define glValidateProgram lcValidateProgram
#define glVertexAttribPointer lcVertexAttribPointer #define glVertexAttribPointer lcVertexAttribPointer
#endif #endif

View file

@ -121,14 +121,17 @@ bool TexFont::Load()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
unsigned char ExpandedData[sizeof(TextureData) * 8]; unsigned char ExpandedData[sizeof(TextureData) * 8 * 2];
for (unsigned int TexelIdx = 0; TexelIdx < sizeof(TextureData) * 8; TexelIdx++) for (unsigned int TexelIdx = 0; TexelIdx < sizeof(TextureData) * 8; TexelIdx++)
ExpandedData[TexelIdx] = TextureData[TexelIdx / 8] & (1 << (TexelIdx % 8)) ? 255 : 0; {
unsigned char Texel = TextureData[TexelIdx / 8] & (1 << (TexelIdx % 8)) ? 255 : 0;
ExpandedData[TexelIdx * 2] = ExpandedData[TexelIdx * 2 + 1] = Texel;
}
mTextureWidth = 128; mTextureWidth = 128;
mTextureHeight = 128; mTextureHeight = 128;
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, mTextureWidth, mTextureHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, ExpandedData); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, mTextureWidth, mTextureHeight, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, ExpandedData);
const unsigned char* Ptr = GlyphData; const unsigned char* Ptr = GlyphData;

View file

@ -821,7 +821,8 @@ void View::DrawRotateOverlay()
Verts[0] = lcVector3(0.0f, 0.0f, 0.0f); Verts[0] = lcVector3(0.0f, 0.0f, 0.0f);
int NumVerts = 1; int NumVerts = 1;
glVertexPointer(3, GL_FLOAT, 0, Verts); mContext->SetVertexBufferPointer(Verts);
mContext->SetVertexFormat(0, 3, 0, 0);
float StartAngle; float StartAngle;
int i = 0; int i = 0;
@ -840,7 +841,7 @@ void View::DrawRotateOverlay()
if (NumVerts == 33) if (NumVerts == 33)
{ {
glDrawArrays(GL_TRIANGLE_FAN, 0, NumVerts); mContext->DrawPrimitives(GL_TRIANGLE_FAN, 0, NumVerts);
Verts[1] = Verts[32]; Verts[1] = Verts[32];
NumVerts = 2; NumVerts = 2;
} }
@ -854,7 +855,7 @@ void View::DrawRotateOverlay()
} while (Angle >= 0.0f); } while (Angle >= 0.0f);
if (NumVerts > 2) if (NumVerts > 2)
glDrawArrays(GL_TRIANGLE_FAN, 0, NumVerts); mContext->DrawPrimitives(GL_TRIANGLE_FAN, 0, NumVerts);
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
@ -882,8 +883,10 @@ void View::DrawRotateOverlay()
mContext->SetColor(0.1f, 0.1f, 0.1f, 1.0f); mContext->SetColor(0.1f, 0.1f, 0.1f, 1.0f);
mContext->SetWorldMatrix(lcMatrix44Identity()); mContext->SetWorldMatrix(lcMatrix44Identity());
glVertexPointer(3, GL_FLOAT, 0, Verts); mContext->SetVertexBufferPointer(Verts);
glDrawArrays(GL_LINE_LOOP, 0, 32); mContext->SetVertexFormat(0, 3, 0, 0);
mContext->DrawPrimitives(GL_LINE_LOOP, 0, 32);
} }
lcVector3 ViewDir = mCamera->mTargetPosition - mCamera->mPosition; lcVector3 ViewDir = mCamera->mTargetPosition - mCamera->mPosition;
@ -953,8 +956,10 @@ void View::DrawRotateOverlay()
} }
} }
glVertexPointer(3, GL_FLOAT, 0, Verts); mContext->SetVertexBufferPointer(Verts);
glDrawArrays(GL_LINES, 0, NumVerts); mContext->SetVertexFormat(0, 3, 0, 0);
mContext->DrawPrimitives(GL_LINES, 0, NumVerts);
} }
// Draw tangent vector. // Draw tangent vector.
@ -1009,13 +1014,16 @@ void View::DrawRotateOverlay()
Verts[4] = lcVector3(0.0f, StartY, EndZ); Verts[4] = lcVector3(0.0f, StartY, EndZ);
Verts[5] = lcVector3(0.0f, StartY - OverlayScale * OverlayRotateArrowCapSize, EndZ + TipZ); Verts[5] = lcVector3(0.0f, StartY - OverlayScale * OverlayRotateArrowCapSize, EndZ + TipZ);
glVertexPointer(3, GL_FLOAT, 0, Verts); mContext->SetVertexBufferPointer(Verts);
glDrawArrays(GL_LINES, 0, 6); mContext->SetVertexFormat(0, 3, 0, 0);
mContext->DrawPrimitives(GL_LINES, 0, 6);
} }
// Draw text. // Draw text.
lcVector3 ScreenPos = ProjectPoint(OverlayCenter); lcVector3 ScreenPos = ProjectPoint(OverlayCenter);
mContext->SetProgram(LC_PROGRAM_TEXTURE);
mContext->SetWorldMatrix(lcMatrix44Identity()); mContext->SetWorldMatrix(lcMatrix44Identity());
mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0))); mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0)));
mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f)); mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f));