Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 19 May 2011
Offline Last Active Apr 24 2016 04:15 PM

Topics I've Started

Sorry, you do not qualify to take this survey

04 September 2015 - 04:10 PM

OK why?

I wanted to take the survey to help out gamedev.net, but appearantly im not qualified.

I chose Sweden -> .NET and then I recieved the message about not being qualified. Didn't even get to know what the survey was about.

Wierd.. What kind of a survey disqualifies you based on your answers? Must be some Technical issue, Right?

*EDIT I see the banner now, it says they want 1 more from Canada and 1 2more from Australia, so I guess it's by design. Wierd, why say no to more data?

degenerate triangles

22 May 2015 - 08:39 AM


I am making a webgl 2d renderer to render quads (sprites).

To make the renderer more effective i minimize draw calls by having all vertex data in the same buffer.

Each vertex has a pos, tintcolor and texcoord, making one vertex (3 * 4 * 2) * 4(float) = 36 bytes.

Max number of sprites per draw call is 10.000.

At the moment i am rendering quads using indices, with drawElemtents and gl_triangle_strips.

Ie: quad one is made up of index 0-1-2 + 1-2-3, quad two of index 4-5-6 + 5-6-7 etc. This seems to be working fine. There is, however no shared vertices. (except those that are shared in a quad)

Looking at other solutions to this kind of batching, a lot of people do not use indices, but instead use drawArrays with gl_triangels and a degenerate triangle to separate quads.

I am looking for some input regarding the differences between the two, and if there are any disadvantages to using indices.

Thanks in advance!

Encapsulation through anonymous namespaces

22 January 2015 - 06:10 AM



When programming in C++ I often (always) use some method of data encapsulation.

This used to mean defining a class, declaring variables and helper functions private and supplying a public interface of member functions:

class A
        int PublicFunction() { return _privateVariable; }
        int _privateVariable;

Any user of this class can create an instance of the class and use its public members.

Should implementation specific details happen to change, the public interface of the class can stay the same. This is all fine.


Howeverm, the more I code, the more I find myself in situations where there only needs to (or only should) ever be one instance of a class.

There are many solutions to this, such as the singleton pattern, classes with static member functions etc.


But somehow these designpatterns have always felt wrong to me. It feels like trying to fit the problem to the solution, where the solution always is some form of a class, be it a singleton or whatever.

This led me to eventually just stop using any "formal" way of data encapsulation in those situations and instead use free functions grouped in a namespace. This approach got rid of the above mentioned "problem", but introduced another problem, which is that variables and methods that should be private were now a part of the public interface*. This is obviously a far bigger issue then not liking a certain design pattern.
Recently, however, I stumbled across anonymous namespaces, which seems to take care of the above mentioned problem:
namespace // private, not accessable from outside this source file
    int privateVariable = 54;
    int PrivateHelperFunction()
        // can change this to whatever i want without breaking the public interface
        return 123;
namespace PublicInterface
    bool PerformSomeAction()
        // Can access "private" varaibles and functions from here:
        return PrivateHelperFunction() == privateVariable;
This seems like a great alternative to using singletons and static classes, and I am using this approach a lot now.
I would like to ask though, if there are any obvious drawbacks or pitfalls that I should be aware of.
One thing that makes me slightly worried is that I have been programming for quite a while in C++ and I never see this coding style being used in examples or even being talked about, which makes me think that there is something "wrong" about it.
potential issues that I can think of:
  • bad (or incorrect) use of namespaces
  • cannot seperate implementation over many source code files (would you even want to do this?)
  • could it make code less reusable maybe?
Thanks in advance for your help!
*if making dll's etc. I guess you could just not export those parts - but this is not the situation I am talking about here

Problem with perspective in opengl

23 November 2014 - 01:21 PM



I am experiencing a perspective problem when rendering a model in OpenGL.

I am pretty sure there is some problem with my MVP matrix, but I am unable to deduce what it could be.


I am using the identity matrix for my model and the projection matrix and view matrix is defined as below:

glm::mat4 _projectionMatrix = glm::perspective(45.0f, _screenDimensions.x / _screenDimensions.y, 0.1f, 100.0f);
glm::mat4 _viewMatrix = glm::lookAt(glm::vec3(4,0,0), glm::vec3(0,0,0), glm::vec3(0,1,0));

they are multiplied and sent to the vertex shader:

auto mvpMatrix =  _projectionMatrix * _viewMatrix * glm::mat4(1.0f);
glUniformMatrix4fv(mvpUniformHandle, 1, GL_FALSE, glm::value_ptr(mvpMatrix));

and used in the shaders:

// Vertex shader
#version 330
layout (location = 0) in vec3 Position;
layout (location = 1) in vec2 TexCoord;
uniform mat4 MVP;
out vec2 TexCoord0;
void main()
    gl_Position = MVP * vec4(Position, 1);
    TexCoord0 = TexCoord;
// Fragment shader

#version 330
precision highp float;
in vec2 TexCoord0;
uniform sampler2D TextureSampler;
out vec4 FragColor;
void main()
    FragColor = texture2D(TextureSampler, TexCoord0.xy);

And the result I am getting can be seen in attached file "wrong.png"


However, when searching for answers I found a post at SO where someone was trying to do something with a raycastand I noticed that the asker had defined his/her projection matrix with the inverse of the aspect ratio, so I tried doing that:

glm::mat4 _projectionMatrix = glm::perspective(45.0f, -(_screenDimensions.x / _screenDimensions.y), 0.1f, 100.0f);

and the results actually seem to be correct! (see attached file "right.png")


I also added files "wrong2.png" and "right2.png" which is the model with some rotation / scaling / translation


But all this makes absolutely 0 sense to me, and makes me think that there is something else that is wrong with my code.

Why would passing a negative aspect ratio make it look as it should (if it even is as it should).


I am fairly certain there is a  problem in either the MVP matrix or how it is used in the shader.

I have used the model data in a webgl application and it rendered just fine there so the vertecies position and texture coord data is fine.


Here is the model loading / passing code for completion sake

// Vertecies, position / texture coord
Vertex vertices[] =
                           // Front face
                           Vertex(glm::vec3(-1.0, -1.0,  1.0), glm::vec2(0.0, 0.0)),
                           Vertex(glm::vec3( 1.0, -1.0,  1.0), glm::vec2(1.0, 0.0)),
                           Vertex(glm::vec3( 1.0,  1.0,  1.0), glm::vec2(1.0, 1.0)),
                           Vertex(glm::vec3(-1.0,  1.0,  1.0), glm::vec2(0.0, 1.0)),
                           // Back face
                           Vertex(glm::vec3(-1.0, -1.0, -1.0), glm::vec2(1.0, 0.0)),
                           Vertex(glm::vec3(-1.0,  1.0, -1.0), glm::vec2(1.0, 1.0)),
                           Vertex(glm::vec3( 1.0,  1.0, -1.0), glm::vec2(0.0, 1.0)),
                           Vertex(glm::vec3( 1.0, -1.0, -1.0), glm::vec2(0.0, 0.0)),
                           // Top face
                           Vertex(glm::vec3(-1.0,  1.0, -1.0), glm::vec2(0.0, 1.0)),
                           Vertex(glm::vec3(-1.0,  1.0,  1.0), glm::vec2(0.0, 0.0)),
                           Vertex(glm::vec3( 1.0,  1.0,  1.0), glm::vec2(1.0, 0.0)),
                           Vertex(glm::vec3( 1.0,  1.0, -1.0), glm::vec2(1.0, 1.0)),
                           // Bottom face
                           Vertex(glm::vec3(-1.0, -1.0, -1.0), glm::vec2(1.0, 1.0)),
                           Vertex(glm::vec3( 1.0, -1.0, -1.0), glm::vec2(0.0, 1.0)),
                           Vertex(glm::vec3( 1.0, -1.0,  1.0), glm::vec2(0.0, 0.0)),
                           Vertex(glm::vec3(-1.0, -1.0,  1.0), glm::vec2(1.0, 0.0)),
                           // Right face
                           Vertex(glm::vec3( 1.0, -1.0, -1.0), glm::vec2(1.0, 0.0)),
                           Vertex(glm::vec3( 1.0,  1.0, -1.0), glm::vec2(1.0, 1.0)),
                           Vertex(glm::vec3( 1.0,  1.0,  1.0), glm::vec2(0.0, 1.0)),
                           Vertex(glm::vec3( 1.0, -1.0,  1.0), glm::vec2(0.0, 0.0)),
                           // Left face
                           Vertex(glm::vec3(-1.0, -1.0, -1.0), glm::vec2(0.0, 0.0)),
                           Vertex(glm::vec3(-1.0, -1.0,  1.0), glm::vec2(1.0, 0.0)),
                           Vertex(glm::vec3(-1.0,  1.0,  1.0), glm::vec2(1.0, 1.0)),
                           Vertex(glm::vec3(-1.0,  1.0, -1.0), glm::vec2(0.0, 1.0))
        glGenBuffers(1, &VBO);
        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

        unsigned int Indices[] =
                         0,  1,  2,    0,  2,  3, // Front face
                         4,  5,  6,    4,  6,  7, // Back face
                         8,  9, 10,    8, 10, 11, // Top face
                        12, 13, 14,   12, 14, 15, // Bottom face
                        16, 17, 18,   16, 18, 19, // Right face
                        20, 21, 22,   20, 22, 23  // Left face
        glGenBuffers(1, &IBO);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);
// Draw function

        glUniformMatrix4fv(mvpUniform, 1, GL_FALSE, glm::value_ptr(mvpMatrix));
        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)0);
        glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)12);

        glBindTexture(_textureTarget, _textureId);

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
        glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);

Anyone have any suggestion as to what could be wrong?


Thanks in advance for your help!

building luabind for gcc 4.8.1

15 January 2014 - 08:25 PM



I hope this is the right forum for this.


I am having some major problems getting luabind to even compile with mingw.

I have searched and followed every tutorial / stackoverflow thread / other documentation available and it doesn't help.


Steps taken:


1. Downloaded boost and build bjam with cmd "bootstrap.bat mingw" (tried versions 1.5.5, 1.5.4 and 1.3.4 same results) 

2. Downloaded lua precompiled binaries (version 4.1.0 since that is supposidly the only one compatible with luabind)

3. Added environment variables BOOST_ROOT and LUA_PATH to their respective value

4. Added bjam path to environment variables

5. Downloaded luabind (tried all versions since 2006) and ran this in cmd "bjam stage toolset=gcc"



"g++"  -ftemplate-depth-128 -O0 -fno-inline -Wall -g  -DLUABIND_BUILDING  -I
"." -I"C:\boost_1_54_0" -I"C:\mingw_dev_lib\lua41\include" -c -o "bin\gcc-mingw-
4.7.1\debug\src\overload_rep.o" "src\overload_rep.cpp"
...failed gcc.compile.c++ bin\gcc-mingw-4.7.1\debug\src\overload_rep.o...
gcc.compile.c++ bin\gcc-mingw-4.7.1\debug\src\stack_content_by_name.o
In file included from ./luabind/wrapper_base.hpp:31:0,
                 from ./luabind/back_reference.hpp:27,
                 from ./luabind/class.hpp:97,
                 from ./luabind/luabind.hpp:28,
                 from src\stack_content_by_name.cpp:25:
./luabind/detail/call_member.hpp:318:1: error: missing binary operator before to
ken "("
In file included from ./luabind/back_reference.hpp:27:0,
                 from ./luabind/class.hpp:97,
                 from ./luabind/luabind.hpp:28,
                 from src\stack_content_by_name.cpp:25:
./luabind/wrapper_base.hpp:90:1: error: missing binary operator before token "("
In file included from ./luabind/detail/constructor.hpp:39:0,
                 from ./luabind/class.hpp:98,
                 from ./luabind/luabind.hpp:28,
                 from src\stack_content_by_name.cpp:25:
./luabind/wrapper_base.hpp:90:1: error: missing binary operator before token "("
In file included from ./luabind/detail/constructor.hpp:41:0,
                 from ./luabind/class.hpp:98,
                 from ./luabind/luabind.hpp:28,
                 from src\stack_content_by_name.cpp:25:
./luabind/detail/signature_match.hpp:151:1: error: missing binary operator befor
e token "("
./luabind/detail/signature_match.hpp:227:1: error: missing binary operator befor
e token "("
In file included from ./luabind/detail/constructor.hpp:42:0,
                 from ./luabind/class.hpp:98,
                 from ./luabind/luabind.hpp:28,
                 from src\stack_content_by_name.cpp:25:
./luabind/detail/call_member.hpp:318:1: error: missing binary operator before to
ken "("
In file included from ./luabind/detail/constructor.hpp:43:0,
                 from ./luabind/class.hpp:98,
                 from ./luabind/luabind.hpp:28,
                 from src\stack_content_by_name.cpp:25:
./luabind/wrapper_base.hpp:90:1: error: missing binary operator before token "("

And it goes on and on with similar messages from different files...


If i run without toolset=gcc it compiles just fine with mcvs.. the .lib and .bin files are there, just like they should be..


I have looked at :




which seems to be related, but it doesn't help my situation.


Someone please help smile.png


Thanks in advance / AS