SFML community forums
Help => Graphics => Topic started by: ravenheart on December 15, 2009, 04:27:24 pm
-
Hello, I´m wondering what the bind() - function exactly does.
Background: I´d like to use sfml for creating OpenGL-textures.
But yet i do not understand what the bind() does.
Are there any restrictions for a texture-image?
E.g. should it be quadratic? Or from the other side:
What is a bad texture-image?
-
Actually, It binds the image exactly like the way you would do with pure OpenGL. It's just flipped vertically.
Somehow, it strangely don't work anymore on SFML2 svn (or it's just me who's missing something)
-
Somehow, it strangely don't work anymore on SFML2 svn
Did you post something about that? If not, you should do it ;)
-
Well here is my second attempt to get a texture working:
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <iostream>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create the main window
sf::Window App(sf::VideoMode(800, 600, 32), "SFML OpenGL");
// Create a clock for measuring time elapsed
sf::Clock Clock;
// Set color and depth clear value
glClearDepth(1.f);
glClearColor(1.f, 0.f, 0.f, 0.f);
// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 8/6, 1.f, 500.f);
sf::Image img;
if(!img.LoadFromFile("/home/anubis/Bilder/holz.jpg"))
std::cout << "Error while loading Image\n";
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
// Resize event : adjust viewport
if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
// Set the active window before using OpenGL commands
// It's useless here because active window is always the same,
// but don't forget it if you use multiple windows or controls
App.SetActive();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Apply some transformations
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f);
glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
img.Bind();
glPushMatrix();
glScalef(20,20,20);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(1.0, 1.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(1.0, -1.0, 0.0);
glEnd();
glPopMatrix();
// Finally, display rendered frame on screen
App.Display();
}
return EXIT_SUCCESS;
}
but my texture doesnt fit the whole square... why is it so?
even when i scale my texture up to 2000^2 pixels the texture doesnt seem complete.
All i want to see is my square with wooden surface ^^
And if .bind() does the same like id do using pure opengl, where can i put extra-options?
[ glTexParameterf(xxx) ?]
im sorry that i dont post sfml-relevant stuff only, but i want to use it for a (very small) opengl-project
(scenegraph-rendering and collada im/export)
-
but my texture doesnt fit the whole square... why is it so?
If the texture doesn't have power of two dimensions, and your graphics card doesn't support it, it is padded with white pixels.
And if .bind() does the same like id do using pure opengl, where can i put extra-options?
After calling Bind().
-
the texture is a picture i downloaded from the internet,
it is scaled to 300*300 px by default (i sometimes change it to see what happens)
the texture appears, so i think that my g-card doesnt have problems with textures.
And the regions not textured appear black, not white
(to see them i changed glearcolor to red)
...
is there some mistake in my code?
i tried even different formats, eg jpg, bmp
(when trying jpg, i sometimes get strange errors (Bad Drawable oder Window-Parameter)
but even with bmp the texture is incomplete but i didnt get any error yet
any idea whats going wrong?
-
And the regions not textured appear black, not white
Actually the padding may be black, I don't really remember :lol:
You should try to resize your texture to 256x256 to be sure.
-
Yeah, thank you.
256*256 does work exactly the way i wnat it to do.
But is there any way t disable padding?
I dont want to scale every Picture id like to use for textures to 256*256.
But if there is no other way...
Well at least it works =)
-
Your graphics card doesn't support textures with non-power-of-two dimensions. So the only other way is to scale the image before sending its pixels to the texture. But it's a good habit to use power-of-two textures anyway.
-
one last question concerning this topic:
how do i use different textures for eg one cube?
bind doesnt seem to work in glBegin() ... glEnd(),
so by now i have to split one cube in 6 calls, so that i can bind another image.
but id like to use something (like with colors) like that:
glBegin(Quads or so)
img.Bind()
texturecoord, vertex;
texturecoord, vertex;
texturecoord, vertex;
texturecoord, vertex;
another_img.bind()
texturecoord, vertex;
texturecoord, vertex;
texturecoord, vertex;
texturecoord, vertex;
glEnd();
by now its like:
img.bind();
glBegin()
...
glEnd()
another img.bind();
glBegin()
...
glEnd();
-
You cannot do much inside glBegin()/glEnd(), only send vertices attributes with glVertex, glColor, etc.
What you can do is to group all the faces inside one bigger texture, and adjust the faces coordinates accordingly.