Chciałem załadować plik, zrobić z niego teksturę aby móc go wyświetlić OpenGL.
Mam taki kod wczytujący:
GLuint LoadTexture(std::string path)
{
GLuint texture;
sf::Image image;
image.loadFromFile(path);
// generowanie nazwy obrazu
//ilGenImages(1, &texture);
// wybranie biezacego obrazu
//ilBindImage(texture);
// ladowanie obrazu z pliku
//ilLoadImage(path);
// konwertowanie tekstury
//if (ilGetInteger(IL_IMAGE_BITS_PER_PIXEL) == 24)ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
//else if (ilGetInteger(IL_IMAGE_BITS_PER_PIXEL) > 24)ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
// obsluga bledow
//if(ilGetError() == IL_NO_ERROR)Errors = "IL ERROR: 0";
//else Errors = "IL ERROR: " + std::to_string(ilGetError());
// generowanie nazwy tekstury
glGenTextures( 1, &texture );
// wybranie biezacej tekstury
glBindTexture( GL_TEXTURE_2D, texture );
// ustalenie parametrów tekstury
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
// ustalenie trybu teksturowania
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
// tworzenie tekstury
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, image.getSize().x,
image.getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
// kasowanie obrazu
//ilDeleteImages(1, &texture);
// obsluga bledow
//if(glGetError() == GL_NO_ERROR)Errors += "-GL ERROR: 0";
//else Errors += "-GL ERROR: " + std::to_string(glGetError());
//return NO_ERROR_FUNC;
return texture;
}
i taki wyświetlający:
void DrawTexture(GLdouble x, GLdouble y, GLdouble width, GLdouble height, GLuint texture)
{
// wybranie biezacej tekstury
glBindTexture( GL_TEXTURE_2D, texture );
// ustalenie koloru kwadratu
glColor3f( 1.0, 0.0, 1.0 );
// rysowanie kwadratu pod teksture
glBegin( GL_QUADS );
glTexCoord2d( 0, 0 );
glVertex2d( x, y );
glTexCoord2d( 1, 0 );
glVertex2d( x + width, y );
glTexCoord2d( 1, 1 );
glVertex2d( x + width, y + height );
glTexCoord2d( 0, 1 );
glVertex2d( x, y + height );
glEnd();
}
Po uruchomieniu programu nic się nie dzieje tylko czarny ekran i tyle.
Czy w SFML trzeba coś ustawić?
EDIT:
Obraz wyświetla się częściowo gdy wywołam funkcje rysującą napis:
int DrawText(float x, float y, std::string text, sf::Font &font, int charactersize,
sf::Text::Style style, sf::Color color, sf::RenderWindow &windoW)
{
sf::Text message;
message.setPosition(x, y);
message.setString(text);
message.setFont(font);
message.setCharacterSize(charactersize);
message.setStyle(style);
message.setColor(color);
windoW.draw(message);
return 0;
}