Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Where is shading statement?

  1. #1
    Senior Member Regular Contributor
    Join Date
    Mar 2015
    Posts
    296

    Question Where is shading statement?

    A simple of color triangle, which data is as follow and produce a colorful triangle. where is color render statement?

    float positionData[] = {
    -0.8f, -0.8f, 0.0f,
    0.8f, -0.8f, 0.0f,
    0.0f, 0.8f, 0.0f };
    //
    float colorData[] = {
    1.0f, 0.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
    0.0f, 0.0f, 1.0f };
    ...
    draw display...
    glBindVertexArray(vaoHandle);
    glDrawArrays(GL_TRIANGLES,0,3);
    glBindVertexArray(0);

    glutSwapBuffers();
    ...
    glBufferData(GL_ARRAY_BUFFER,9 * sizeof(float),
    colorData,GL_STATIC_DRAW);

    glGenVertexArrays(1,&vaoHandle);
    glBindVertexArray(vaoHandle);

    glEnableVertexAttribArray(0);//
    glEnableVertexAttribArray(1);//vertex color

    glBindBuffer(GL_ARRAY_BUFFER, positionBufferHandle);
    glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL )

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674
    Have you considered reading some learning material about OpenGL, rather than just doing stuff and asking whenever you don't know what's going on? It would probably be a better use of everyone's time if you sought out some decent learning resources.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2015
    Posts
    296
    Quote Originally Posted by Alfonse Reinheart View Post
    Have you considered reading some learning material about OpenGL, rather than just doing stuff and asking whenever you don't know what's going on? It would probably be a better use of everyone's time if you sought out some decent learning resources.
    thank you. but find nothing in so many docs, or where is it for the matter?
    want to know where is the algorithm statement in the shadering?

  4. #4
    Senior Member Regular Contributor
    Join Date
    Mar 2015
    Posts
    296
    well, from draw begin.

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,651
    Quote Originally Posted by reader1 View Post
    where is color render statement? ... find nothing in so many docs, or where is it for the matter?
    want to know where is the algorithm statement in the shadering?
    It's not clear what you're asking about. What do you mean "color render statement"? Please clarify.

    Are you asking for how the color vertex attribute array gets passed into the GPU shader program, or the portion of the shader program which pertains to generating the per-fragment color?

    Related: Are you using the compatibility profile? Does your program define its own shaders? Why does your source code snippet only show loading the color VBO and only show binding the position VBO? If it's not too long, post the full source for this short test program in [highlight=cpp]...[/highlight] or [code]...[/code] blocks.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Mar 2015
    Posts
    296
    Here it is,

    GLuint p,f,v;

    void setShaders() {
    char *vs,*fs;
    v = glCreateShader(GL_VERTEX_SHADER);
    f = glCreateShader(GL_FRAGMENT_SHADER);
    vs = textFileRead("moon.vert");
    fs = textFileRead("moon.frag");
    const char * vv = vs;
    const char * ff = fs;
    glShaderSource(v, 1, &vv, NULL);
    glShaderSource(f, 1, &ff, NULL);
    free(vs);free(fs);
    glCompileShader(v);
    glCompileShader(f);
    p = glCreateProgram(); //
    glAttachShader(p,v);
    glAttachShader(p,f);
    glLinkProgram(p);
    glUseProgram(p);
    }

    void initVBO()
    {
    // Create and populate the buffer objects
    GLuint vboHandles[2];
    glGenBuffers(2, vboHandles);
    GLuint positionBufferHandle = vboHandles[0];
    GLuint colorBufferHandle = vboHandles[1];

    glBindBuffer(GL_ARRAY_BUFFER,positionBufferHandle) ;
    glBufferData(GL_ARRAY_BUFFER,9 * sizeof(float),
    positionData,GL_STATIC_DRAW); //坐标数据到VBO

    glBindBuffer(GL_ARRAY_BUFFER,colorBufferHandle);
    glBufferData(GL_ARRAY_BUFFER,9 * sizeof(float),
    colorData,GL_STATIC_DRAW); //色彩数据到VBO

    glGenVertexArrays(1,&vaoHandle); //建立VAO。
    glBindVertexArray(vaoHandle);

    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    glBindBuffer(GL_ARRAY_BUFFER, positionBufferHandle); //see below
    glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL );

    glBindBuffer(GL_ARRAY_BUFFER, colorBufferHandle);
    glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL );
    }

    void display()
    {
    glClear(GL_COLOR_BUFFER_BIT);
    //VAO、VBO
    glBindVertexArray(vaoHandle);
    glDrawArrays(GL_TRIANGLES,0,3); //is it here?
    glBindVertexArray(0);

    glutSwapBuffers();
    }

    int main(int argc,char** argv)
    {
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(600,600);
    glutInitWindowPosition(100,100);
    glutCreateWindow("GLSL Test : Draw a triangle");
    setShader();
    initVBO();
    glutDisplayFunc(display);

    glutMainLoop();
    return 0;
    }

  7. #7
    Senior Member Regular Contributor
    Join Date
    Mar 2015
    Posts
    296
    glDrawArrays() shows a colorful triangle, but it has only three sest of vertex and color, where the triangle got a gradual shading color?

  8. #8
    Member Contributor
    Join Date
    Oct 2014
    Posts
    55
    It's interpolated between the vertex and fragment shader.


    You should really work through a book and learn opengl proper instead of asking every little bit in this forum. It is not possible to learn something complex like opengl that way.
    Don't expect people teaching you this api, this is not how forums work. Just take the time it needs to work through a book.

  9. #9
    Senior Member Regular Contributor
    Join Date
    Mar 2015
    Posts
    296
    Quote Originally Posted by Betrayal View Post
    It's interpolated between the vertex and fragment shader.


    You should really work through a book and learn opengl proper instead of asking every little bit in this forum. It is not possible to learn something complex like opengl that way.
    Don't expect people teaching you this api, this is not how forums work. Just take the time it needs to work through a book.
    Its obviously interpolating ioperation! but where is it showed in the above program is what I want to know.
    I check the api function, but find no clue.
    Could you shed a tiny light on it? or which book or doc can prompt it? if you were familiar with it.

  10. #10
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674
    I will say this: neither the OpenGL Wiki search nor Google were terribly useful in finding the answer. Oh sure, I know that the answer was in the fourth result in Google when searching for "OpenGL Interpolation". But I only knew that because I knew what I was looking for already.

    However, I just fixed the OpenGL Wiki to be more helpful in this question. Searching for "Interpolation" takes you to a disambiguation page, the first version of which links you directly to what you need to know.

    Namely, that interpolation is not controlled by an "api function" but by shaders. That's why you couldn't find it; you were looking in the wrong place.

    That being said, this thread was absolutely terrible from the first post. That post made it very difficult to determine what you were asking for. You said something about "color render function", which doesn't make any sense. Furthermore, the code you posted was sufficiently broken that nobody could tell what you were looking for without you further clarifying it.

    Indeed, it took until the 7th post that it became marginally clear what you were looking for. In response to something you said in post #8, no, it is not clear that interpolation was happening, because you failed to explain what was going on or what you were interested in discovering.

    In the future, please spend more time formulating your question so that it's at least clear what information you're looking for. If you're not going to actually follow any of the tutorials that would explain all this stuff to you (note: there's a difference between actually following a tutorial and just scanning through it for an answer to your current problem. Don't use tutorials for the latter), then you could at least try to ask a whole and complete question that clearly explains what your problem is.

Page 1 of 2 12 LastLast

Similar Threads

  1. GLSL; return statement ...
    By tmason in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 02-26-2015, 09:58 AM
  2. goto statement
    By roger512 in forum OpenCL
    Replies: 1
    Last Post: 05-10-2013, 08:19 AM
  3. Why the hell is this If statement being ignored?
    By halo in forum OpenGL: GLSL
    Replies: 2
    Last Post: 12-28-2006, 08:42 PM
  4. IF statement causes FPS drop!
    By hardtop in forum OpenGL: GLSL
    Replies: 1
    Last Post: 02-15-2006, 01:24 AM
  5. Is the if-statement particularly slow ?
    By wizzo in forum OpenGL: GLSL
    Replies: 20
    Last Post: 07-22-2004, 11:02 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