Results 1 to 3 of 3

Thread: Drawing a vbo without using an enabled shader ?

  1. #1
    Member Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    59

    Drawing a vbo without using an enabled shader ?

    Hello,

    1- I would like to know how it works...

    I am drawing a 3D model in a perspective view with a background. (no problem)

    To do that I first draw the background :
    Code :
    glClear(...)
    glOrtho(...)
    disable my shader
     
    // draw the background : a simple rectangle with colors in a vbo
    glBindBuffer(GL_ARRAY_BUFFER,1)
    glVertexPointer(3,GL_FLOAT,0,00000000)
    glEnableClientState(GL_VERTEX_ARRAY)
    glBindBuffer(GL_ARRAY_BUFFER,2)
    glColorPointer(3,GL_FLOAT,0,00000000)
    glEnableClientState(GL_COLOR_ARRAY)
    glDrawArrays(GL_QUADS,0,8) GLSL=6 
    glDisableClientState(GL_COLOR_ARRAY)
    glDisableClientState(GL_VERTEX_ARRAY)
    glBindBuffer(GL_ARRAY_BUFFER,0)
     
    enable my shader

    Then I draw the 3D scene :
    I have opengl 1.1 code with glvertex(...) functions.
    In my shader version 110 (vertex + fragment) :
    - I retrieve the vertex with the built-in variable gl_Vertex.
    - I do not use attribute variables. I only use uniform variables.
    - I use one uniform variable "myObjectColor" to set the color : gl_FragColor = myObjectColor;


    Question :
    Must I disable my shader before drawing my background ?
    In other words : does my shader "see" my vbo ? Is it doing something ? Are the built-in variable gl_Vertex and gl_Color well defined ?

    If the shader does something I think that I have to disable it because my uniform variable to set the color is not set during the background drawing.

    2- This second question is only valid if the shader can be keeped enabled during the background drawing :
    I tested without disabling the shader. It seems to work well except for the first frame : the background is black. After the first refresh it is ok.
    I tried to see what is missing with glintercept but i haven't seen anything... But something is wrong...
    What can cause that ?

    Thanks for your advices.

  2. #2
    Member Contributor
    Join Date
    Mar 2014
    Location
    San Jose, CA
    Posts
    58
    Your shader will be used for all draw calls as long as it's enabled. So you will need a different (very simple) shader to draw your background, or disable the shader completely if you're ok with using the fixed pipeline.

  3. #3
    Member Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    59
    You confirm what I thought.
    So I searched why my views are not coherent with that.
    I found that my shader is disabled after the first frame, which explains the background is well drawn after the first frame.

    Now it is coherent and it helped me to understand other things.
    Thanks for your answer.

Similar Threads

  1. Replies: 19
    Last Post: 03-22-2017, 10:09 AM
  2. Drawing with Compute Shader
    By john_connor in forum OpenGL: GLSL
    Replies: 8
    Last Post: 09-30-2016, 01:18 AM
  3. Drawing without attrib array enabled gets "optimized out" by AMD driver?
    By JakobProgsch in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 10-04-2012, 07:47 AM
  4. opengl 3.x shader only drawing ?
    By lobbel in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-20-2010, 07:30 PM
  5. Drawing a box with the Geometry Shader
    By ViolentHamster in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 08-10-2010, 12:10 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
  •  
Proudly hosted by Digital Ocean