Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - Nvveen

Pages: [1]
1
Graphics / GetPixelsPtr() and glTexImage2D
« on: April 21, 2011, 07:17:06 pm »
Hehe, funny you should mention that, I just checked, and the values are the  same across the program and across the FreeImage values too.

2
Graphics / GetPixelsPtr() and glTexImage2D
« on: April 21, 2011, 06:44:19 pm »
Hello,
I'm trying to switch from using freeglut and Freeimage to SFML. The first step involved loading images from a self created .dat file as a sf::Image object, and passing it into a texture in OpenGL 3.2. The image does get loaded properly, seeing as I can save it and it shows correctly. However, when I call glTexImage2D with GetPixelsPtr() as the data array, my program crashes when it tries to draw the array in OpenGL with glDrawArrays. Mind you, the sf::Image stuff is the only piece of code I have implemented so far. When I was using FreeImage, I could get an array of BYTES (unsigned chars) and pass it to the texture. As far as I understand it, GetPixelsPtr returns a similar array.

I've printed the values in the FreeImage and sf::Image byte arrays both to files to see if there were any odd values, and apart from different values (FreeImage stores its image data somewhat differently I think), I can't see anything out of the ordinary. The code that involves binding to the texture is this:
Code: [Select]

#include    <iostream>
#include    <cstdlib>
#include    <GL/glew.h>
#include    "Texture.h"

//-----------------------------------------------------------------------------
//       Class:  Texture
//      Method:  Texture
// Description:  constructor
//-----------------------------------------------------------------------------
Texture::Texture ()
{
}  // -----  end of method Texture::Texture  (constructor)  -----

//-----------------------------------------------------------------------------
//       Class:  Texture
//      Method:  Texture
// Description:  constructor
//-----------------------------------------------------------------------------
Texture::Texture ( GLenum textureTarget, const sf::Image& png ) :
    textureTarget_(textureTarget), png_(png)
{
    width_ = png_.GetWidth();
    height_ = png_.GetHeight();
}  // -----  end of method Texture::Texture  (constructor)  -----

//-----------------------------------------------------------------------------
//       Class:  Texture
//      Method:  Texture
// Description:  destructor
//-----------------------------------------------------------------------------
Texture::~Texture ()
{
} // -----  end of method Texture::Texture  -----

//-----------------------------------------------------------------------------
//       Class:  Texture
//      Method:  load
// Description:  Loads a targa image from the file.
//-----------------------------------------------------------------------------
    void
Texture::load ()
{
    glGenTextures(1, &texID);
    glBindTexture(textureTarget_, texID);
    glTexParameteri(textureTarget_, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(textureTarget_, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexImage2D(textureTarget_, 0, GL_RGBA, width_, height_, 0, GL_RGBA,
                 GL_UNSIGNED_BYTE, png_.GetPixelsPtr()); // This is where it fails
   
    // Unbind everything
    glBindTexture(textureTarget_, 0);
} // -----  end of method Texture::load  -----

//-----------------------------------------------------------------------------
//       Class:  Texture
//      Method:  bind
// Description:  Binds the texture data into the shaders
//-----------------------------------------------------------------------------
    void
Texture::bind ( const GLuint& shader )
{
    glBindTexture(textureTarget_, texID);
    GLuint gSampler = glGetUniformLocation(shader, "gSampler");
    glUniform1i(gSampler, 0);
} // -----  end of method Texture::bind  -----

Pages: [1]
anything