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

Author Topic: Image and OpenGL does not work  (Read 2814 times)

0 Members and 2 Guests are viewing this topic.

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Image and OpenGL does not work
« on: November 27, 2012, 08:21:14 pm »
Hi, I am using Image as texture source from .tga file but it does not work correctly. One texture is working great, but the second, that is loaded first, is showing only by going closer. Where can be the problem please? :-\
sf::Image image;
                image.loadFromFile(matProp.textureFile);
                GLuint generatedTex = 0;
                glGenTextures(1, &generatedTex);
                glBindTexture(GL_TEXTURE_2D, generatedTex);
                glTexImage2D(GL_TEXTURE_2D,
                             0,
                             GL_RGBA,
                             image.getSize().x,
                             image.getSize().y,
                             0,
                             GL_RGBA,
                             GL_UNSIGNED_BYTE,
                             image.getPixelsPtr());
                //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
                //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
                glGenerateMipmap(GL_TEXTURE_2D);
                matProp.texture = generatedTex;

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Image and OpenGL does not work
« Reply #1 on: November 27, 2012, 10:39:30 pm »
It seems to me like clipping/lighting is set in a way that it turns black at a certain distance, but I've no idea how OpenGL works... ;D

Ehrm don't you want to use a real texture: sf::Texture?
There's a difference between sf::Image and sf::Texture; of course if you really want to use the pixel array you need to use a sf::Image, but sf::Texture has a bind() function, so you can easily use it with your OpenGL code. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Image and OpenGL does not work
« Reply #2 on: November 28, 2012, 06:52:42 am »
I do not have any lighting there  :D . I had sf::Texture in the first, but I have to change quality so I have to use sf::Image.

// EDIT I have just changed the image size from 204x204 to 128x128 and it works good now :D.
« Last Edit: November 28, 2012, 09:17:13 am by reDo »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Re: Image and OpenGL does not work
« Reply #3 on: November 28, 2012, 10:01:50 am »
I do not have any lighting there
Well there's definitely some very basic lighting goong on, otherwise the top and left surface of a box wouldn't be darker than the front ine. ;)

// EDIT I have just changed the image size from 204x204 to 128x128 and it works good now :D.
Nof sure why that fixed it, but I'm glad it did. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Image and OpenGL does not work
« Reply #4 on: November 28, 2012, 10:31:14 am »
No, I do not implement or use any prebuilded lighting, I am sure, I think it is caused by the mipmapping  ;)