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

Author Topic: SFML2 and external gui library  (Read 2172 times)

0 Members and 1 Guest are viewing this topic.

codder

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML2 and external gui library
« on: February 06, 2012, 10:11:53 pm »
Hi all,

I'm trying to work with librocket and sfml but I can't render both things...

Code: [Select]


void CGUIRenderInterface::resize()
{
mWindow->SetActive();

static sf::View View;
View.SetViewport(sf::FloatRect(0, (float)mWindow->GetWidth(), (float)mWindow->GetHeight(), 0));
mWindow->SetView(View);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, mWindow->GetWidth(), mWindow->GetHeight(), 0, -1, 1);
glMatrixMode(GL_MODELVIEW);

glViewport(0, 0, mWindow->GetWidth(), mWindow->GetHeight());
}

void CGUIRenderInterface::RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, const Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation)
{
mWindow->SetActive();

glPushMatrix();
glTranslatef(translation.x, translation.y, 0);

std::vector<Rocket::Core::Vector2f> Positions(num_vertices);
std::vector<Rocket::Core::Colourb> Colors(num_vertices);
std::vector<Rocket::Core::Vector2f> TexCoords(num_vertices);

for(int  i = 0; i < num_vertices; i++)
{
Positions[i] = vertices[i].position;
Colors[i] = vertices[i].colour;
TexCoords[i] = vertices[i].tex_coord;
};

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(2, GL_FLOAT, 0, &Positions[0]);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, &Colors[0]);
glTexCoordPointer(2, GL_FLOAT, 0, &TexCoords[0]);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

sf::Texture* image = (sf::Texture *)texture;

if(image)
{
image->Bind();
}
else
{
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, 0);
};

glDrawElements(GL_TRIANGLES, num_indices, GL_UNSIGNED_INT, indices);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

glColor4f(1, 1, 1, 1);

glPopMatrix();
}


problem is here....

If I comment resize function sfml draw his things but librocket no.

Haikarainen

  • Guest
SFML2 and external gui library
« Reply #1 on: February 12, 2012, 02:21:57 am »
Do you save and restore gl states?

Elgan

  • Jr. Member
  • **
  • Posts: 77
    • AOL Instant Messenger - Flat+1,+17+st+Cl
    • View Profile
SFML2 and external gui library
« Reply #2 on: February 12, 2012, 03:17:09 pm »
I had no problems when I tried rocket...the example had some problems but still worked, but the resize func was messed.


try removing just this:

Code: [Select]


   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0, mWindow->GetWidth(), mWindow->GetHeight(), 0, -1, 1);
   glMatrixMode(GL_MODELVIEW);