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

Author Topic: Quick Question about OpenGL  (Read 4420 times)

0 Members and 2 Guests are viewing this topic.

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Quick Question about OpenGL
« 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?

retep998

  • Newbie
  • *
  • Posts: 17
    • View Profile
Quick Question about OpenGL
« Reply #1 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.

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Quick Question about OpenGL
« Reply #2 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

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Quick Question about OpenGL
« Reply #3 on: December 16, 2010, 12:39:33 am »
If you use SFML2 then you can bind an image as a texture using the renderer.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Quick Question about OpenGL
« Reply #4 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

retep998

  • Newbie
  • *
  • Posts: 17
    • View Profile
Quick Question about OpenGL
« Reply #5 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

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Quick Question about OpenGL
« Reply #6 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

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
Quick Question about OpenGL
« Reply #7 on: December 18, 2010, 01:50:22 am »
In OpenGL, (0,0) is the bottom left.

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Quick Question about OpenGL
« Reply #8 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

Terrydil

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Quick Question about OpenGL
« Reply #9 on: December 18, 2010, 04:35:44 pm »
Is your background an image or are you just setting it with glClear?

retep998

  • Newbie
  • *
  • Posts: 17
    • View Profile
Quick Question about OpenGL
« Reply #10 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.

 

anything