Results 1 to 9 of 9

Thread: One - sided objects/textures

  1. #1
    Guest

    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 =)

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: One - sided objects/textures

    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.
    Code :
    glCullFace(GL_FRONT);
    glEnable(GL_CULL_FACE);
    glBindTexture(...);
    glEnable(GL_TEXTURE_2D);
    DrawQuad(...);
    glDisable(GL_TEXTURE_2D);
    glCullFace(GL_BACK);
    DrawQuad(...);
    glCullFace(GL_FRONT);
    glDisable(GL_CULL_FACE);
    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.

  3. #3
    Guest

    Re: One - sided objects/textures

    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.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: One - sided objects/textures

    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.
    Code :
    glCullFace(GL_FRONT);
    glEnable(GL_CULL_FACE);
    glBindTexture(...);
    glEnable(GL_TEXTURE_2D);
    DrawQuad(...);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_CULL_FACE);
    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.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Dec 1969
    Location
    Munich,Germany
    Posts
    227

    Re: One - sided objects/textures

    wouldn't glPolygonMode(GL_FRONT) do the same????
    yes

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: One - sided objects/textures

    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.

  7. #7
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: One - sided objects/textures

    Bob is right, and glPolygonMode(GL_FRONT) would return an GL_INVALID_ENUM.

  8. #8
    Guest

    Re: One - sided objects/textures

    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.

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: One - sided objects/textures

    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

    >>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.

Similar Threads

  1. Scops of Textures and other GL objects
    By Godspeed in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 06-03-2016, 07:17 AM
  2. objects in opengl appear single sided
    By naisan in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-15-2008, 02:05 PM
  3. reflections on single sided objects
    By jide in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 04-06-2006, 01:03 AM
  4. Loading objects and textures
    By Decebal in forum OpenGL: Linux
    Replies: 5
    Last Post: 10-24-2003, 05:41 PM
  5. Multiple textures for objects
    By Geespot in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-07-2002, 02:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean