Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Using OpenGL draw calls with sfml image's  (Read 1007 times)

0 Members and 1 Guest are viewing this topic.

Whitewolfang1

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Using OpenGL draw calls with sfml image's
« on: January 25, 2013, 11:35:47 am »
Ok so im new to this forum so i hope im not doing anything wrong in regards to forum rules. ive searched all over for similar problems to mine but to no avail. i am trying to bind a sf::image and then use glbegin(GL_QUADS) to draw the image to screen, this is working with other images but not this specific image, i have run through the debugger and am sure that the image has not lost scope as it still knows all data regarding the image, yet whilst every other image i draw to screen works, this does not draw anything, similarly i have tried drawing a simple GL quad without binding an image and only using glcolor, it draws the quad in the correct position and all but it is mostly transparent and is dark green regardless of what glcolor i input. i really hope this is some kind of newbish mistake, its driving me crazy.
void TileSet_Manager::Render()
{
///////////////////////////////////////////////////
///this is working and draws all images correctly
////////////////////////////////////////////////
   for (int i = 0 ; i < TotalTiles;++i)
   {
      Tiles[i].Render();
   }
//////////////////////////////////////////////////////
/////this however draws nothing
/////////////////////////////////////////////////////
   float X = m_Min.GetX();
   float Y = m_Min.GetY();

   float X2 = m_Max.GetX();
   float Y2 = m_Min.GetY();

   Menu->Bind();

   glBegin(GL_QUADS);

   glColor4f(1.0f,0.0f,0.0f,1.0f);

   glTexCoord2f(0,0);
   glVertex2f(X,Y);

   glTexCoord2f(1,0);
   glVertex2f(X2,Y);

   glTexCoord2f(1,1);
   glVertex2f(X2,Y2);

   glTexCoord2f(0,1);
   glVertex2f(X,Y2);

   glColor4f(1.0f,1.0f,1.0f,1.0f);

   glEnd();

   float x = currSelected->GetPos().GetX();
   float y = currSelected->GetPos().GetY();

   currSlcBox->Bind();
/////////////////////////////////////////////////////////
//this just draws a semi transparent green box regardless whether or not i use gl color
/////////////////////////////////////////////////////////
   glBegin(GL_QUADS);

   glVertex2f(x - TileSize/2 - 1,y - TileSize/2 - 1);

   glVertex2f(x + TileSize/2 + 1,y - TileSize/2 - 1);

   glVertex2f(x + TileSize/2 + 1,y + TileSize/2 + 1);

   glVertex2f(x - TileSize/2 - 1,y + TileSize/2 + 1);

   glEnd();
}
 
and here is the code for Tile.render()
void Tile::Render()
{
   m_TileTexture->Bind();

   float U1 = m_MinUV.GetX();
   float V1 = m_MinUV.GetY();

   float U2 = m_MaxUV.GetX();
   float V2 = m_MaxUV.GetY();

   glBegin(GL_QUADS);

   glTexCoord2f(U1,V1);
   glVertex2f(m_Pos.GetX() - TileSize/2,m_Pos.GetY() - TileSize/2);

   glTexCoord2f(U2,V1);
   glVertex2f(m_Pos.GetX() + TileSize/2, m_Pos.GetY() - TileSize/2);

   glTexCoord2f(U2,V2);
   glVertex2f(m_Pos.GetX() + TileSize/2, m_Pos.GetY() + TileSize/2);

   glTexCoord2f(U1,V2);
   glVertex2f(m_Pos.GetX() - TileSize/2, m_Pos.GetY() + TileSize/2);

   glEnd();
}
furthermore ive gone through the VS Debugger step by step and made sure that all variables such as m_Pos and U1,V1,U2 etc are all correct. why do the tiles draw but the menu image doesnt, ive changed what image it loads and it still doesnt work.
« Last Edit: January 26, 2013, 12:55:00 am by Whitewolfang1 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Using OpenGL draw calls with sfml image's
« Reply #1 on: January 25, 2013, 05:37:40 pm »
Any error message in the console? Did the LoadFromFile function return true?
Laurent Gomila - SFML developer

Whitewolfang1

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Using OpenGL draw calls with sfml image's
« Reply #2 on: January 25, 2013, 10:47:36 pm »
No error message in console and LoadFromFile returns true. I also placed a breakpoint where it calls bind and the pixel array has data in it. Im using multiple projects together with the main one being a win32, im dynamically linking the project's and sfml libraries. Could any of this cause the issues? Thanks.

Whitewolfang1

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Using OpenGL draw calls with sfml image's
« Reply #3 on: January 26, 2013, 02:50:57 am »
nvm solved it, cant believe i was so stupid
        float X = m_Min.GetX();
        float Y = m_Min.GetY();

        float X2 = m_Max.GetX();
        float Y2 = m_Min.GetY();
 

Y2 and Y were the same =_= thanks
Now im embarrassed

 

anything