1
General / How to draw a simple sprite with OpenGL?
« on: February 14, 2015, 08:34:16 pm »
Hello, im new to OpenGL, and so far, i am able to draw a triangle with this simple code:
But how do i put a texture on it? I have read the tutorial here at the bottom of the page
http://www.sfml-dev.org/tutorials/2.2/graphics-sprite.php
I have created a texture, loaded it, and then call
sf::Texture::bind(&texture);
But my triangle is still white.
glClearColor(1,0,0,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2d(-0.5f, -0.5f);
glVertex2d(0, 0.5f);
glVertex2d(0.5f, -0.5f);
glEnd();
window.display();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2d(-0.5f, -0.5f);
glVertex2d(0, 0.5f);
glVertex2d(0.5f, -0.5f);
glEnd();
window.display();
But how do i put a texture on it? I have read the tutorial here at the bottom of the page
http://www.sfml-dev.org/tutorials/2.2/graphics-sprite.php
I have created a texture, loaded it, and then call
sf::Texture::bind(&texture);
But my triangle is still white.