Results 1 to 3 of 3

Thread: Drawing 1 textured object and 1 un-textured object

  1. #1

    Drawing 1 textured object and 1 un-textured object

    I am looking at the Textured Box demo https://cvs.khronos.org/svn/repos/regis ... itBox.html listed on http://khronos.org/webgl/wiki/Demo_Repository

    I'd like to add a white square without texture to this demo so it will have 1 textured object (the original demo) and 1 object without texture.

    The demo has the following code to texture the cube
    Code :
    <script id="fshader" type="x-shader/x-fragment">
    #ifdef GL_ES
        precision mediump float;
    #endif
     
        uniform sampler2D sampler2d;
     
        varying float v_Dot;
        varying vec2 v_texCoord;
     
        void main()
        {
            vec2 texCoord = vec2(v_texCoord.s, 1.0 - v_texCoord.t);
            vec4 color = texture2D(sampler2d, texCoord);
            color += vec4(0.1, 0.1, 0.1, 1);
            gl_FragColor = vec4(color.xyz * v_Dot, color.a);
        }
    </script>

    What do I need to do to draw the white square without texture?

    Thanks in advance for your help.

  2. #2

    Re: Drawing 1 textured object and 1 un-textured object

    I have just seen this article Passing a variable to a OpenGL GLSL shader http://stackoverflow.com/questions/2514 ... le-in-glsl

    I just pass a flag to the shader. It seems that it does what I want.

    Please let me know if there is a better way.

  3. #3
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: Drawing 1 textured object and 1 un-textured object

    Code :
    <script id="fshader" type="x-shader/x-fragment">
    #ifdef GL_ES
        precision mediump float;
    #endif
        varying float v_Dot;
     
        void main()
        {
            gl_FragColor = vec4 ( vec3(1,1,1)*v_Dot, 1 ) ;
        }
    </script>

    The vec3(1,1,1) is the color of the object (in this case, white), multiplying it by v_Dot (which is, presumably, the lighting brightness from the vertex shader) applies lighting to the object, and the last '1' sets the alpha to fully-opaque.

Similar Threads

  1. Drawing masked sprites (textured quad with alpha channel)
    By lucafr in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 02-07-2012, 09:39 AM
  2. How to get point stripes function to with textured polygons?
    By mobilevisuals in forum OpenGL ES 1.X - fixed function hardware
    Replies: 3
    Last Post: 10-26-2009, 12:35 AM

Posting Permissions

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