c++ - Box2D body with OpenGL texture origin offset in GLFW -


I think this is common knowledge for all those people who use Box2D and OpenGL that the origin of Box2D bodies In the center of the body and the open glyph texture, it is in the bottom left corner. I am using Box2D to create a body and to attach a OpenGL texture with the function,

glTranslatef (Player_Body-> GetPosition (.x), Player_Body-> GetPosition (.), 0.0f)

However, since GetPosition () returns the original, so my texture is attached to its lower left corner in the center of the body. How do I change the origin of OpenGL texture to the center of texture?

I do not think this is nothing but a screen conversion from the world. So far, at least not because I'm not performing any physics, just display a stable body. Currently, the ratio is meters: pixels -> 1: 1 (I know this is bad behavior, but this is just a temporary test). My program uses GLFW as a windowing system. I used GLUT earlier, it appeared correctly, but I had a monitor device problem with GLUT, so I am using GLFW. The OpenGL code remains the same for drawing and conversion. So if the box is a 2D code, how can I solve it?

P.S. : I am not posting any code because it is more of a logic related question. But if necessary I will post.

Do not think about it as the origin of texture, but rather the origin of the texture that makes it Displays the rectangle.

In OpenGL, the coordinates of textures are defined by the specification, where there is a coordinating place where the texture is root in the lower-left corner, you can change your vertical position in the object space. Without the code, I suppose that your corner is defined as (0, 0) as (w, h) when you create them In object space, this means that a rectangle is at the origin of a corner and it is in a quarter. From your glTranslatef call object space takes the corner to the world space.

You should change your corner instead, so that the center of the rectangle is in the form of object space i.e. (-w / 2, -h / 2) to (w / 2, h / 2) , at that point when you translate the object object object, then in the original center.

Here's a scene of what I'm talking about (in the visual object):

  | | | ***** | | ***** | | ***** ***** ----------------- & lt; Current ------ ***** ------ & lt; New | ***** | | | | | |  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -