9
« on: October 11, 2010, 09:07:36 am »
im using windows xp sp3 with mingw32 and sfml and having an issue with this program that appears to steadily eat up memory while minimized.
everything runs fine and doesnt appear to be leaking when the window visible, its only when its minimized to taskbar AND when trying to draw more than 1 image, but it is fine with only 1 image.
#include <SFML/Graphics.hpp>
#include <GL/gl.h>
void InitOpenGL(){
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glViewport(0, 0, 640, 480);
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST) ;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(0.0f, 640.0f, 480.0f, 0.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void DrawImage(GLuint texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h){
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex2f(x, y);
glTexCoord2f(1.0f, 0.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex2f(x+w, y);
glTexCoord2f(1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex2f(x+w, y+h);
glTexCoord2f(0.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex2f(x, y+h);
glEnd();
}
GLuint CreateTexture(std::string image_path){
sf::Image temp_image;
temp_image.LoadFromFile(image_path);
GLuint temp_texture;
glGenTextures(1, &temp_texture);
glBindTexture(GL_TEXTURE_2D, temp_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, temp_image.GetWidth(), temp_image.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, temp_image.GetPixelsPtr());
return temp_texture;
}
int main (){
sf::RenderWindow app;
bool is_running = true;
sf::Event event;
app.Create(sf::VideoMode(640, 480, 32), "Test App");
InitOpenGL();
GLuint test1, test2;
test1 = CreateTexture("test1.png");
test2 = CreateTexture("test2.png");
while (is_running){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
app.GetEvent(event);
if (event.Type == sf::Event::Closed)
is_running = false;
DrawImage(test1, 0, 0, 64, 64);
DrawImage(test2, 320, 0, 64, 64);
app.Display();
}
return 0;
}
i am aware of the sf::Sprite class but i would rather use opengl myself if i can. been trying to only use sfml for window creation, events, and image loading.
would greatly appreciate if someone can point out my error or something.