31
Graphics / Converting Image to GLuint (a texture)
« on: August 31, 2009, 03:47:59 pm »
The program crashes.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
GLuint ScreenImage()
{
sf::Image img;
img.CopyScreen(App,sf::IntRect(0,0,512,256));
const sf::Uint8* ptr = img.GetPixelsPtr();
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,512,256,0,GL_RGBA,GL_UNSIGNED_INT,ptr);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
return tex;
}
yes but dynamic linking "boost" performance with Linux ( at least it doesn't decrease performances ) .
#include <SFML/Graphics.hpp>
#include <string>
using namespace std;
sf::RenderWindow App;
sf::Sprite load_sprite(string path)
{
sf::Sprite test_sprite;
sf::Image img;
img.LoadFromFile(path);
test_sprite.SetImage(img);
return test_sprite;
}
//#define fromFunction // Un-comment the #define to make the image load incorrectly.
#ifdef _WIN32
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
#else
int main()
#endif
{
App.Create(sf::VideoMode(640, 480, 32), "SFML Window");
sf::Sprite spr;
#ifdef fromFunction
spr = load_sprite("image.bmp");
#else
sf::Image bobf;
bobf.LoadFromFile("image.bmp");
spr.SetImage(bobf);
#endif
spr.SetCenter(120,80);
spr.SetScale(1,1);
spr.SetColor(sf::Color(255,255,255));
spr.SetX(320);
spr.SetY(240);
bool loopin = true;
while(loopin)
{
sf::Event Event;
while (App.GetEvent(Event))
{
if ((Event.Type == sf::Event::Closed) || ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)))
{
App.Close();
loopin = false;
break;
}
}
App.Draw(spr);
App.Display();
sf::Clock clock;
clock.Reset();
while(clock.GetElapsedTime() < 1/60)
{}
}
return EXIT_SUCCESS;
}