Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Pixel Position world space

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    7

    Pixel Position world space

    Hi guys,

    I am wondering if somebody can help.
    I've got a list of quads, few of them got a flag and in the pixel shader I need to be able
    to colour the quad with a flag half red and half black (just two random colors).
    Probably when I render I need to understand when I am in the middle of my quad
    but I don't know how to do it.

    cheers.

  2. #2
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    7
    I think it's the local space not the world, but the concept should be clear even with this error.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    942
    Simple solution, texture coordinates.

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    7
    Using a texture was my first thought unfortunately I can't I've got only the vbo with vertex, normal and color.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    942
    You don't need a texture if you only have two clearly defined colors. And you can define the coords yourself quite easily: You've got quads - made up of four vertices. That's all you need to know. Define the coordinates, put them in the VBO and use the texture coordinates to decide how to color the quad.

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    7
    Quote Originally Posted by thokra View Post
    You don't need a texture if you only have two clearly defined colors. And you can define the coords yourself quite easily: You've got quads - made up of four vertices. That's all you need to know. Define the coordinates, put them in the VBO and use the texture coordinates to decide how to color the quad.
    Ok two colors was only to simplify, at the end is going to be more complex I tried to do something like that :

    float value = gl_TexCoord[0].s;

    if(value<0.5)
    {

    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
    }

    else
    {
    gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
    }

    But it does not work, I am missing something.

  7. #7
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    7
    Quote Originally Posted by thokra View Post
    You don't need a texture if you only have two clearly defined colors. And you can define the coords yourself quite easily: You've got quads - made up of four vertices. That's all you need to know. Define the coordinates, put them in the VBO and use the texture coordinates to decide how to color the quad.
    I think I start to understand now, I will try soon.

    thanks.

  8. #8
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    7
    it works! thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •