It is currently Tue Jul 25, 2017 1:49 am

All times are UTC - 5 hours




 Page 1 of 1 [ 5 posts ] 
Author Message
 Post subject: Shader VMK 76 - Textured Gui Image
PostPosted: Fri Mar 13, 2015 7:24 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1102
Location: Ontario Canada
In this video I show how to add a texture to a GuiImage object. I also update the GuiLoader class to handle the need to work with textures directly inside the gui text file.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 76 - Textured Gui Image
PostPosted: Tue May 05, 2015 2:59 pm 

Joined: Fri Aug 22, 2014 3:54 pm
Posts: 17
So I got the code working for this tutorial, but it looks like something is... somewhat wrong with mine. The same images show up, but mine appear to be squished slightly. Do you have idea where I should look to find what might be causing this? I went through the entire loadTGA function and I looked back through the generateVerticies function in GuiImageElement. It all appears correct when I compare it to the original video. Any ideas? An image of my results are below.

http://postimg.org/image/xfdy4addv/

As a reference, maybe I missed something. Here is my generageVerticies.
void GuiImageElement::GenerateVertices(const glm::uvec2& fillsize){
   _vertices.clear();

   if (_config.uTextureId == INVALID_UNSIGNED ||
      _size.x == 0 || _size.y == 0 ||
      _textureSize.x == 0 || _textureSize.y == 0){
      _vertices.push_back(GuiVertex(glm::vec2(), _color)); // Top Left
      _vertices.push_back(GuiVertex(glm::vec2(0, fillsize.y), _color)); // Bottom Left
      _vertices.push_back(GuiVertex(glm::vec2(fillsize.x, 0), _color)); // Top Right
      if (GL_TRIANGLES == _config.uRenderType){
         _vertices.push_back(_vertices[2]);
         _vertices.push_back(_vertices[1]);
      }
      _vertices.push_back(GuiVertex(glm::vec2(fillsize.x, fillsize.y), _color));
   }
   else {
      glm::vec2 position;
      glm::uvec2 desiredFillSize;
      // Stretch the image to take up the entire fill size area
      if (_isStretched){
         desiredFillSize = fillsize;
      } else {
         position = glm::vec2((fillsize.x - _size.x) >> 1, (fillsize.y - _size.y) >> 1);
         desiredFillSize = _size;
      }

      float factorX = 1.0f / static_cast<float>(_textureSize.x);
      float factorY = 1.0f / static_cast<float>(_textureSize.y);

      glm::vec2 texCoordBottomLeft = glm::vec2(factorX*(_origin.x),
                                     factorY*(_textureSize.y - _origin.y - _size.y));
      glm::vec2 texCoordTopRight    = glm::vec2(factorX*(_origin.x + _size.x),
                                     factorY*(_textureSize.y - _origin.y));
      _vertices.push_back(GuiVertex(   position,
                              _color,
                              glm::vec2(texCoordBottomLeft.x, texCoordTopRight.y)));

      _vertices.push_back(GuiVertex(   glm::vec2(position.x,
                              position.y + desiredFillSize.y),
                              _color,
                              texCoordBottomLeft));

      _vertices.push_back(GuiVertex(   glm::vec2(position.x + desiredFillSize.x,
                              position.y),
                              _color,
                              texCoordTopRight));
      if (_config.uRenderType == GL_TRIANGLES){
         _vertices.push_back(_vertices[2]);
         _vertices.push_back(_vertices[1]);
      }

      _vertices.push_back(GuiVertex(   glm::vec2(   position.x + desiredFillSize.x,
                                       position.y + desiredFillSize.y),
                                       _color,
                                       glm::vec2(texCoordTopRight.x, texCoordBottomLeft.y)));
   }

   // Save positions
   _vPosition.clear();
   for each(const GuiVertex& vertex in _vertices){
      _vPosition.push_back(vertex.position);
   }
   _offsetPosition = glm::ivec2();
}


Offline
 Profile  
 
 Post subject: Re: Shader VMK 76 - Textured Gui Image
PostPosted: Tue May 05, 2015 4:56 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 448
You code here looks fine, I did not see any apparent errors. Which version of GLM are you using?


Offline
 Profile  
 
 Post subject: Re: Shader VMK 76 - Textured Gui Image
PostPosted: Tue May 05, 2015 7:31 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1102
Location: Ontario Canada
You are getting the full texture rendered but your size is squished in both X and Y directions. What I would do if I were you is create a fixed size GuiImage with no texture just a solid color. Get a print-screen of the output window and take a look at the size in an image editor. Are you getting the requested size? Also what does the console tell you your GuiImage size is supposed to be? Does it match your output? That should start to point you in the direction in which you should look for the bug.

Also check your glViewport settings and your glm::ortho setting


Offline
 Profile  
 
 Post subject: Re: Shader VMK 76 - Textured Gui Image
PostPosted: Wed May 06, 2015 1:25 pm 

Joined: Fri Aug 22, 2014 3:54 pm
Posts: 17
Marek wrote:
You are getting the full texture rendered but your size is squished in both X and Y directions. What I would do if I were you is create a fixed size GuiImage with no texture just a solid color. Get a print-screen of the output window and take a look at the size in an image editor. Are you getting the requested size? Also what does the console tell you your GuiImage size is supposed to be? Does it match your output? That should start to point you in the direction in which you should look for the bug.

Also check your glViewport settings and your glm::ortho setting



Spot on Marek! My glm::ortho was using the window pixel size instead of the game pixel size. That fixed the issue. Thanks for the insight!


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron