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

Author Topic: Converting Image to GLuint (a texture)  (Read 4088 times)

0 Members and 1 Guest are viewing this topic.

wademcgillis

  • Newbie
  • *
  • Posts: 36
    • View Profile
Converting Image to GLuint (a texture)
« on: August 31, 2009, 04:10:38 am »
Code: [Select]

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;
    }

what am I doing wrong?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Converting Image to GLuint (a texture)
« Reply #1 on: August 31, 2009, 08:20:19 am »
Quote
what am I doing wrong?

GL_UNSIGNED_INT should be GL_UNSIGNED_BYTE, so that you don't depend on the machine's endianness.

The result may also depend on where in your main loop you call this function.

Giving a little more informations could be useful (at least, what do you get with your current code?).
Laurent Gomila - SFML developer

wademcgillis

  • Newbie
  • *
  • Posts: 36
    • View Profile
Converting Image to GLuint (a texture)
« Reply #2 on: August 31, 2009, 03:47:59 pm »
The program crashes.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Converting Image to GLuint (a texture)
« Reply #3 on: August 31, 2009, 03:54:36 pm »
What does the debugger say?
Laurent Gomila - SFML developer

wademcgillis

  • Newbie
  • *
  • Posts: 36
    • View Profile
Converting Image to GLuint (a texture)
« Reply #4 on: August 31, 2009, 07:52:08 pm »
GL_UNSIGNED_BYTE solved the problem. It works fine now. I put GL_UNSIGNED_INT because of Uint8*.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Converting Image to GLuint (a texture)
« Reply #5 on: September 01, 2009, 01:11:00 pm »
Quote from: "wademcgillis"
It works fine now. I put GL_UNSIGNED_INT because of Uint8*.
And guess how many bits a byte contains... ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

wademcgillis

  • Newbie
  • *
  • Posts: 36
    • View Profile
Converting Image to GLuint (a texture)
« Reply #6 on: September 01, 2009, 04:14:17 pm »
Byte: 8
Short: 16
Float: 32
Int: 32?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Converting Image to GLuint (a texture)
« Reply #7 on: September 01, 2009, 04:22:20 pm »
I think that OpenGL constants for types do not make any assumption about their size, they just map to the system's native types. So GL_UNSIGNED_INT could be either 32 bits or 64 bits depending on the target machine.
Laurent Gomila - SFML developer