1
Graphics / sf::Image.LoadFromFile might be causing invalid pointers?
« on: February 25, 2010, 12:38:24 pm »
Wow, thanks. It worked. =)
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.
Quote from: "OniLink10"I've done a comparison of Game Maker and SFML before. SFML was much faster at everything. It's most likely your code. Also, your code is VERY messy and unsafe. You call new a lot but I don't see you calling delete anywhere!
How do I call new "a lot"? Each new only gets called once, it's not like it's a memory leak since the game goes out of memory when it closes.
Also, my code is very readable in my perspective. I'd probably think your code is very messy too.
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main() {
sf::Window window(sf::VideoMode(800, 600), "Rendering", sf::Style::Close);
sf::Image image;
//Problem line....
if(!image.LoadFromFile("Texture.png")) {
return 1;
}
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.GetWidth(), image.GetHeight(),
0, GL_RGB, GL_UNSIGNED_BYTE, image.GetPixelsPtr());
glClearDepth(1.0f);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, 1.0f, 1.0f, 500.0f);
while (window.IsOpened()) {
sf::Event evnt;
while(window.GetEvent(evnt)) {
switch(evnt.Type) {
case sf::Event::Closed:
window.Close();
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_TRIANGLES);
glColor4f(0.0f,255.0f,255.0f,255.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor4f(255.0f,0.0f,255.0f,255.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor4f(255.0f,255.0f,0.0f,255.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
glTranslatef(3.0f,0.0f,0.0f);
glRotatef(-25.0f, 0.0f, 1.0f, 0.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureID);
glBegin(GL_QUADS);
glTexCoord2f(1.0f,1.0f);
glVertex3f( -1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f,0.0f);
glVertex3f(-1.0f,0.0f, 0.0f);
glTexCoord2f(1.0f,0.0f);
glVertex3f( 0.0f,0.0f, 0.0f);
glTexCoord2f(1.0f,1.0f);
glVertex3f( 0.0f,1.0f, 0.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
window.Display();
}
}
return EXIT_SUCCESS;
}
Unhandled exception at 0x737a84b4 in OpenGL render.exe: 0xC0000005: Access violation reading location 0x003e9000.