1
Graphics / SFML2 deriving the Drawable class
« on: April 19, 2012, 05:02:59 am »
I'm probably going to get shot down for this (given my level of ignorance), but I'll ask away.
I'm trying to derive the drawable class with an object that makes calls to OpenGL directly.
And I'm trying to render a real basic sprite (for starters).
draw function definition
Start up, which just sets up OpenGL
Main Loop code:
I'm not sure what I'm missing (do I need setup for rendering something this? I'm not sure what to do). I do see it (the BaseSprite) flashing but then disappearing afterwords.
Is anyone willing to suggest anything?
Please don't angry with me, if this post is undeserving just tell me and I'll move on (eventually, hopefully).
Thanks for tips
I'm trying to derive the drawable class with an object that makes calls to OpenGL directly.
And I'm trying to render a real basic sprite (for starters).
draw function definition
Code: [Select]
void BaseSprite::draw(sf::RenderTarget & target, sf::RenderStates states) const
{
glEnable(GL_TEXTURE_2D);
// Set the primitive color to white
glColor4f(1.f, 1.f, 1.f, 1.f);
// Bind the texture
glBindTexture(GL_TEXTURE_2D, myTexture->id());
glPushMatrix(); // Save modelview matrix
acl::PointF center = myBounds.center();
glTranslatef(center.x, center.y, 0.f);
glRotatef(0.f, 0.f, 0.f, 0.f);
glTranslatef(myBounds.x - center.x, myBounds.y - center.y, 0.f);
glBegin(GL_QUADS);
glTexCoord2f(0.f , myTextureBounds.h);
glVertex2f (0.f , 0.f );
glTexCoord2f(myTextureBounds.w, myTextureBounds.h);
glVertex2f (myBounds.w , 0.f );
glTexCoord2f(myTextureBounds.w, 0.f );
glVertex2f (myBounds.w , myBounds.h );
glTexCoord2f(0.f , 0.f );
glVertex2f (0.f , myBounds.h );
glEnd();
glPopMatrix();
}
Start up, which just sets up OpenGL
Code: [Select]
Graphics::instance().enable2d();
Main Loop code:
Code: [Select]
app.draw(txt); // a test sf::Text object
app.pushGLStates();
app.draw(bs); // which is a BaseSprite object
app.popGLStates();
I'm not sure what I'm missing (do I need setup for rendering something this? I'm not sure what to do). I do see it (the BaseSprite) flashing but then disappearing afterwords.
Is anyone willing to suggest anything?
Please don't angry with me, if this post is undeserving just tell me and I'll move on (eventually, hopefully).
Thanks for tips