glstuff

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 7d226c22eb249b50801bec01c716d0a4abf7930d
parent dd9ad1dc98f23eb51f5aeff5e68fe783959f9645
Author: Brian Swetland <swetland@frotz.net>
Date:   Tue, 29 Jan 2013 01:05:40 -0800

cleanup and fixes

- add a release build to vcx project
- DisableAttribArrays after use to avoid crashing
- expose fps as a global
- display fps in debugtext

Diffstat:
MDebugText.cc | 3+++
Mglue.h | 3++-
Mprojects/test5/test5.vcxproj | 13+++++++++++++
Msdlglue.cc | 3+++
Mtest5.cc | 11+++++++++--
5 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/DebugText.cc b/DebugText.cc @@ -150,6 +150,9 @@ int DebugText::render(void) { glEnableVertexAttribArray(aTexCoord); glDrawArrays(GL_TRIANGLES, 0, cbw * cbh * 6); + glDisableVertexAttribArray(aVertex); + glDisableVertexAttribArray(aTexCoord); + return 0; } diff --git a/glue.h b/glue.h @@ -48,6 +48,7 @@ GLXTN PFNGLBUFFERDATAPROC glBufferData; GLXTN PFNGLCOMPILESHADERPROC glCompileShader; GLXTN PFNGLCREATEPROGRAMPROC glCreateProgram; GLXTN PFNGLCREATESHADERPROC glCreateShader; +GLXTN PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray; GLXTN PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; GLXTN PFNGLGENBUFFERSPROC glGenBuffers; GLXTN PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation; @@ -71,7 +72,7 @@ struct { const char *name; } fntb[] = { EFUNC(glActiveTexture), EFUNC(glAttachShader), EFUNC(glBindBuffer), EFUNC(glBufferData), - EFUNC(glCompileShader), EFUNC(glCreateProgram), EFUNC(glCreateShader), + EFUNC(glCompileShader), EFUNC(glCreateProgram), EFUNC(glCreateShader), EFUNC(glDisableVertexAttribArray), EFUNC(glEnableVertexAttribArray), EFUNC(glGenBuffers), EFUNC(glGetAttribLocation), EFUNC(glGetProgramiv), EFUNC(glGetProgramInfoLog), EFUNC(glGetShaderiv), EFUNC(glGetShaderInfoLog), EFUNC(glGetUniformLocation), EFUNC(glLinkProgram), EFUNC(glShaderSource), diff --git a/projects/test5/test5.vcxproj b/projects/test5/test5.vcxproj @@ -89,6 +89,19 @@ <Command>xcopy /y "$(ProjectDir)..\libraries\x64-debug\*.dll" "$(OutDir)"</Command> </PostBuildEvent> </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <AdditionalIncludeDirectories>..\libraries\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <AdditionalLibraryDirectories>../libraries/x64-debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <AdditionalDependencies>libpng.lib;zlib.lib;SDL.lib;SDLmain.lib;OpenGL32.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Windows</SubSystem> + </Link> + <PostBuildEvent> + <Command>xcopy /y "$(ProjectDir)..\libraries\x64-debug\*.dll" "$(OutDir)"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> <ItemGroup> <ClCompile Include="..\..\DebugText.cc" /> <ClCompile Include="..\..\loadfile.cc" /> diff --git a/sdlglue.cc b/sdlglue.cc @@ -142,6 +142,8 @@ void handle_events(void) { } } +int fps = 0; + int main(int argc, char **argv) { int vsync = 1; struct ctxt c; @@ -235,6 +237,7 @@ int main(int argc, char **argv) { t1 = time(0); count++; if (t0 != t1) { + fps = count; printf("%d fps\n", count); count = 0; t0 = t1; diff --git a/test5.cc b/test5.cc @@ -50,6 +50,8 @@ float a = 0.0; struct model *m; +extern int fps; + int scene_init(struct ctxt *c) { float aspect = ((float) c->width) / ((float) c->height); @@ -138,10 +140,10 @@ int scene_draw(struct ctxt *c) { glBindBuffer(GL_ARRAY_BUFFER, 0); glVertexAttribPointer(aVertex, 3, GL_FLOAT, GL_FALSE, 8*4, m->vdata); - glEnableVertexAttribArray(aVertex); glVertexAttribPointer(aNormal, 3, GL_FLOAT, GL_FALSE, 8*4, m->vdata + 3); - glEnableVertexAttribArray(aNormal); glVertexAttribPointer(aTexCoord, 2, GL_FLOAT, GL_FALSE, 8*4, m->vdata + 6); + glEnableVertexAttribArray(aVertex); + glEnableVertexAttribArray(aNormal); glEnableVertexAttribArray(aTexCoord); Model.identity().translate(20, 40, 30); @@ -173,9 +175,14 @@ int scene_draw(struct ctxt *c) { glUniformMatrix4fv(uMVP, 1, GL_FALSE, MVP); glDrawElements(GL_TRIANGLES, m->icount, GL_UNSIGNED_SHORT, m->idx); + glDisableVertexAttribArray(aVertex); + glDisableVertexAttribArray(aNormal); + glDisableVertexAttribArray(aTexCoord); + debugtext.clear(); debugtext.printf("Hello, Test #5\n"); debugtext.printf("Cam @ %6.3f %6.3f\n", camx, camz); + debugtext.printf("\n%d fps\n", fps); debugtext.render(); return 0;