Jump to content

  • Log In with Google      Sign In   
  • Create Account

Texture Coordinates Problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 f12dude   Members   -  Reputation: 121

Like
0Likes
Like

Posted 25 March 2013 - 12:42 AM

I'm converting my DirectX text renderer to OpenGL, and I've run into an issue with the texture coordinates. My problem is that the text that gets rendered in OpenGL is flipped horizontally. I was wondering how this came to be as after reading about how OpenGL texture corrdinates work, I would have thought that I would have needed to invert the V component of the texture coordinates, but this seems to be not the case.



Sponsor:

#2 blueshogun96   Crossbones+   -  Reputation: 1095

Like
0Likes
Like

Posted 25 March 2013 - 04:03 AM

All you have to do to is take the V component and subtract it from 1.0.  This will properly invert your texture coordinates

 

float s = u;

float t = 1.0f - v;

 

Have you tried this before?  If this doesn't work, you might want to share a bit of code with us.

 

Shogun.


Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png

 

"Yo mama so fat, she can't be frustum culled." - yoshi_lol


#3 GeneralQuery   Crossbones+   -  Reputation: 1263

Like
0Likes
Like

Posted 25 March 2013 - 04:37 AM

At a superficial glance DirectX and OpenGL appear to have different texture space origins but this isn't necessarily the case, the pointer you pass to function glTexImage2D points to the lower-left texel of the texture so to flip the origin you need only upload a flipped version of your texture data (probably the best for GL/D3D uniformity) or transform the origin in your shader.

 

However, this does not address the fact that your textures are being flipped horizontally. What is flipped? The individual characters or the texture itself?



#4 f12dude   Members   -  Reputation: 121

Like
0Likes
Like

Posted 25 March 2013 - 10:52 AM

This is what the flipping looks like when rendering "1234567890"

 

The code is essentially the same as the DirectX version which treats the origin in the top left.

 

wu1gsm.png



#5 blueshogun96   Crossbones+   -  Reputation: 1095

Like
0Likes
Like

Posted 25 March 2013 - 11:06 AM

Then try inverting the U coordinate.  Have you tried that?

 

Shogun.


Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png

 

"Yo mama so fat, she can't be frustum culled." - yoshi_lol


#6 GeneralQuery   Crossbones+   -  Reputation: 1263

Like
0Likes
Like

Posted 25 March 2013 - 11:13 AM

Is each glyph a seperate quad? Are you sure you're being consistent with your coordinate system handidness between the two implementations?

#7 f12dude   Members   -  Reputation: 121

Like
0Likes
Like

Posted 25 March 2013 - 01:26 PM

I figured a solution to the problem by changing my view matrix, but I'm not sure if this is the correct way to go about this:

 

glm::lookAt(glm::vec3(0.0f,0.0f,-10.0f),glm::vec3(0.0f,0.0f,0.0f),glm::vec3(0.0f,1.0f,0.0f));

 

 

Changed to:

 

glm::lookAt(glm::vec3(0.0f,0.0f,10.0f),glm::vec3(0.0f,0.0f,0.0f),glm::vec3(0.0f,1.0f,0.0f));

Edited by f12dude, 25 March 2013 - 01:26 PM.


#8 GeneralQuery   Crossbones+   -  Reputation: 1263

Like
0Likes
Like

Posted 25 March 2013 - 02:35 PM

You need to be consistent with your conventions between APIs. By inverting the direction of your view matrix you are effectively changing the handedness of your coordinate system, hence the reason why your text was being "flipped" back round the right way. It appears that you have culling disabled which is why you could still see the text in your original "flipped" image (albeit incorrectly rendered), otherwise you would be staring at an empty frame buffer (the glyph quads would have been culled as technically they were facing away from the camera). There's other subtle issue to consider so get things consistent otherwise you'll trip yourself up again in the not-so-distant future.



#9 f12dude   Members   -  Reputation: 121

Like
0Likes
Like

Posted 25 March 2013 - 03:29 PM

I've enabled back face culling and only half of the triangles get rendered.  I've also reverted my view matrix back to what I originally had it set to.  I'm still new to this but in DirectX, I would specify CullMode= CCW; in the shader to do backface culling which worked correctly. I still have no idea how to get the text rendered correctly without flipping the view matrix. Inverting the U component of the texture coordinates does this(without culling):

 

int x = character % 16; // Column
int y = (character / 16); // Row

glm::vec2 topLeft(1.0f - (x / 16.0f),y / 16.0f);
glm::vec2 bottomRight(1.0f - ((x+1) / 16.0f),(y+1) / 16.0f);

 

 

 

23r1lb7.jpg


Edited by f12dude, 25 March 2013 - 03:32 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS