View Full Version : One - sided objects/textures
Alright, this is kinda hard to explain, but I'll try. I have a 2D square.. it's just a plain GL_QUAD with 4 vertices. Now, I want to throw a texture onto this square. This is no problem, of course. The thing is, I want the texture to show up on one side, but not the other. Imagine this: the square is standing up in front of you.. and it has a texture of bricks on it. You walk "through" the square and are on the other side. When you turn around to look at the square again, you don't see anything because there is no texture on that side.
I'm not sure if there is a way to achieve this affect. Right now I'm using GL_TEXTURE_2D for everything, I've seen GL_Texture_1D around.. does that only draw one side? I tried to get some of that working, but couldn't seem to get going with it.
I guess I'm just asking if this is possible at all before I go waste a bunch of time. Any ideas anyone? Thanks a bunch =)
GL_TEXTURE_2D is for mapping a two dimensional texture onto a surface, GL_TEXTURE_1D is used to map a one dimensional texture. This is not what you want.
You can enable backface culling, bind your texture and draw the quad. Then you set the backface to be visible, disable texturing, and draw the quad again.
Be aware that you have to pass your vertices in counter clockwise order. This is because CCW is the default winding order in OpenGL, and CCW-faces is front facing by default.
Hmm maybe I'm missing something here. This seems to be on the right track, because it's not drawing the texture on the back side now. However, the square is now white on that side, instead of having a texture. I was hoping to get nothing at all.. totally see - through square. Is that what I should be getting with the code you have? I dunno if there's some other setting I should change, or if whiteness is what you intended.
Ok, so you don't want the quad to show up at all if it's facing the wrong direction? Then do like this instead.
I got the impression you wanted the texture to show up only on one side of the quad, but not in the other but the quad itself should be drawn.
03-23-2001, 03:44 AM
wouldn't glPolygonMode(GL_FRONT) do the same????
glPolygonMode is used to control how the polygon is drawn. As point in the cornes, as lines in the edges, or filled. So no, it won't be the same.
03-23-2001, 07:39 AM
Bob is right, and glPolygonMode(GL_FRONT) would return an GL_INVALID_ENUM.
Sweet, that works like a charm! Exactly what I needed.
One thing I'm having problems with though is counter - clockingwise vectors. I thought I'd be fine just starting at the bottom left of the square and going counter - clockwise from there, as if I were looking at it straight on. This doesn't work too well.. if I go by Nehe's tutorial on lighting/texture mapping.. his square always draws countery-clockwise, but the points start in different places. The way he does it works.
I guess I'm asking.. does it matter what vector you start with.. if it doesn't, I must have been doing something else wrong.
No, it does not matter what vertex you start drawing from. In fact, OpenGL has no clue at all if it's the lower left, upper right, or any other vertex. Just swap the order of the vertices if you are calling them in the wrong order http://www.opengl.org/discussion_boards/ubb/smile.gif
>>and glPolygonMode(GL_FRONT) would return an GL_INVALID_ENUM
Not correct, it wouldn't compile at all, because glPolygonMode requires TWO arguments. Besides that, GL_FRONT (alogn with GL_BACK and GL_FRONT_AND_BACK) is a perfectly valid for the FIRST argument. The second one must be GL_POINT, GL_LINE or GL_FILL.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.