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

Author Topic: SFML and OPENGL co-ordinate  (Read 1964 times)

0 Members and 1 Guest are viewing this topic.

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
SFML and OPENGL co-ordinate
« on: June 09, 2011, 08:22:31 pm »
Hi,
     using Sprite.SetPosition(10,10) will set the sprite at 10,10 from the left top corner.

But in the same window if i use glVertex2f(10.0,10.0)  it will get placed in some other position with reference to the centre of the screen (Opengl)


How to related it, like taking the SFML co-ordinate as reference the Opengl prmitives should also be drawn at the same place. eg

Sprite.SetPosition(10.0, 10.0);   and glVertex2f(10.0,10.0) at the same place

How to make it happen???

All suggestions are welcome

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML and OPENGL co-ordinate
« Reply #1 on: June 09, 2011, 08:45:57 pm »
It must be done in a derived sf::Drawable class, otherwise you won't get the modelview and projection matrices that SFML uses to draw stuff.
Laurent Gomila - SFML developer

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
SFML and OPENGL co-ordinate
« Reply #2 on: June 09, 2011, 09:21:56 pm »
Quote from: "Laurent"
It must be done in a derived sf::Drawable class, otherwise you won't get the modelview and projection matrices that SFML uses to draw stuff.


Can you elaborate a little more please!!

you mean
Code: [Select]

class Block : public sf::Drawable
{
  Draw();
}

void Block::Draw()
{
       glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//if the particle is still alive, then draw
glPushMatrix();
glTranslatef((iter)->m_ParticlePosition.x, (iter)->m_ParticlePosition.y, -400.0f);

glRotatef((iter)->m_Angle,0,0,1);
//glScalef(1.0f, 1.0f, 1.0f);
glColor4ub((iter)->m_Color.r, (iter)->m_Color.g, (iter)->m_Color.b, (iter)->m_Color.a);
glBegin(GL_QUADS);
glTexCoord2f(texCoords.Left,  texCoords.Top); glVertex2f(-halfWidth, -halfHeight);
glTexCoord2f(texCoords.Left,  texCoords.Bottom); glVertex2f(-halfWidth, halfHeight);
glTexCoord2f(texCoords.Right, texCoords.Bottom); glVertex2f(halfWidth, halfHeight);
glTexCoord2f(texCoords.Right, texCoords.Top); glVertex2f(halfWidth, -halfHeight);
glEnd();
glColor4ub(255, 255, 255, 255);
glPopMatrix();


}


Is this what u mean???

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML and OPENGL co-ordinate
« Reply #3 on: June 09, 2011, 10:25:00 pm »
Nop.

sf::Renderer has one virtual function (Render), you must override it.
Laurent Gomila - SFML developer

 

anything