SFML community forums

Help => General => Topic started by: Fierce_Dutch on December 15, 2010, 03:19:42 am

Title: Quick Question about OpenGL
Post by: Fierce_Dutch on December 15, 2010, 03:19:42 am
Well I am trying to create a class called Block. The blocks are all the same but with different textures. With the texture is there anyway I can use just sfml to put an image on the block and have it pretty much glued on. Also here is my real question, how do i manipulate one shape? The constructor of this class will call all of the verts but if I want to call glrotate3f or gltranslate3f. How would I go about manipulating just that shape? Would I need my own matrix? Or would I just call glMatrixMode(MODEL_VIEW) or whatever it is and then translate. And it would know what shape I am talking about or not?
Title: Quick Question about OpenGL
Post by: retep998 on December 15, 2010, 07:03:43 am
Okay, first of all, use newlines to separate your questions. A solid chunk of text is hard to read and follow.
Now then...
"Well I am trying to create a class called Block. The blocks are all the same but with different textures."
So they basically have a member variable specifying the texture.
"With the texture is there anyway I can use just sfml to put an image on the block and have it pretty much glued on."
No, sfml does not do that for you. You should give your block class a draw function which binds whatever texture is specified by the texture member variable and then draws your block.
"Also here is my real question, how do i manipulate one shape? The constructor of this class will call all of the verts but if I want to call glrotate3f or gltranslate3f. How would I go about manipulating just that shape? Would I need my own matrix? Or would I just call glMatrixMode(MODEL_VIEW) or whatever it is and then translate."
glPushMatrix
Do your manipulations
Draw the shape
glPopMatrix
"And it would know what shape I am talking about or not?"
OpenGL has no idea what you want. It just does as its told. So you have to make sure you draw the shape after you do the manipulations but before you pop the matrix again.
Title: Quick Question about OpenGL
Post by: Fierce_Dutch on December 16, 2010, 12:09:52 am
Quote from: "retep998"
Okay, first of all, use newlines to separate your questions. A solid chunk of text is hard to read and follow.
Now then...
"Well I am trying to create a class called Block. The blocks are all the same but with different textures."
So they basically have a member variable specifying the texture.
"With the texture is there anyway I can use just sfml to put an image on the block and have it pretty much glued on."
No, sfml does not do that for you. You should give your block class a draw function which binds whatever texture is specified by the texture member variable and then draws your block.
"Also here is my real question, how do i manipulate one shape? The constructor of this class will call all of the verts but if I want to call glrotate3f or gltranslate3f. How would I go about manipulating just that shape? Would I need my own matrix? Or would I just call glMatrixMode(MODEL_VIEW) or whatever it is and then translate."
glPushMatrix
Do your manipulations
Draw the shape
glPopMatrix
"And it would know what shape I am talking about or not?"
OpenGL has no idea what you want. It just does as its told. So you have to make sure you draw the shape after you do the manipulations but before you pop the matrix again.



Ok on that last part.. How would I bind a texture to each side? I have it setup like this..

bind texture(GL_2D_TEXTURE,&sidetexture) //or somthing like that.
side - 4 verts
side
side
side

bind texture(GL_2D_TEXTURE,&bottomtexture)

bottom - 4verts

bind texture(GL_2D_TEXTURE,&toptexture) or somthing like that.

top - 4 verts
Title: Quick Question about OpenGL
Post by: Groogy on December 16, 2010, 12:39:33 am
If you use SFML2 then you can bind an image as a texture using the renderer.
Title: Quick Question about OpenGL
Post by: Fierce_Dutch on December 17, 2010, 02:40:47 am
Quote from: "Groogy"
If you use SFML2 then you can bind an image as a texture using the renderer.


OK thx, what is a cube map btw? like GL_TEXTURE_CUBE_MAP_POSITIVE_Z?
because i tried to do that and it didnt work
Title: Quick Question about OpenGL
Post by: retep998 on December 17, 2010, 11:15:44 am
Don't bother using cube maps.
Load all you sf::Images and then you can do
someimage.Bind();
glBegin(GL_QUADS);
your vertices
glEnd();
anotherimage.Bind();
glBegin(GL_QUADS);
your vertices
glEnd();
and so on
Title: Quick Question about OpenGL
Post by: Fierce_Dutch on December 17, 2010, 04:23:28 pm
Quote from: "retep998"
Don't bother using cube maps.
Load all you sf::Images and then you can do
someimage.Bind();
glBegin(GL_QUADS);
your vertices
glEnd();
anotherimage.Bind();
glBegin(GL_QUADS);
your vertices
glEnd();
and so on


Ok I am texturing and binding directly with gl with mimaps and my images are gettting flipped
Title: Quick Question about OpenGL
Post by: tntexplosivesltd on December 18, 2010, 01:50:22 am
In OpenGL, (0,0) is the bottom left.
Title: Quick Question about OpenGL
Post by: Fierce_Dutch on December 18, 2010, 02:49:03 am
Quote from: "tntexplosivesltd"
In OpenGL, (0,0) is the bottom left.


ok i flipped them now but whenver i do flip them it makes my bg white
Title: Quick Question about OpenGL
Post by: Terrydil on December 18, 2010, 04:35:44 pm
Is your background an image or are you just setting it with glClear?
Title: Quick Question about OpenGL
Post by: retep998 on December 18, 2010, 05:21:39 pm
Make sure you flipped the texture coordinates, not the vertex coordinates.
If you flip the vertex coordinates the whole primitive faces the other direction and if you have culling enabled (you probably do because you're having this issue), then the texture never gets drawn and you see whatever crap is behind it.