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 )

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?

well, from draw begin.

[QUOTE=reader1;1264903]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?[/QUOTE]
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 [noparse]

...

or

...

[/noparse] blocks.

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§;
glUseProgram§;
}

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;
}

glDrawArrays() shows a colorful triangle, but it has only three sest of vertex and color, where the triangle got a gradual shading color?

as well as this function,
glShaderSource — Replaces the source code in a shader object

glShaderSource — Replaces the source code in a shader object
C Specification
void glShaderSource( GLuint shader,
GLsizei count,
const GLchar **string,
const GLint *length);
Parameters
shader
Specifies the handle of the shader object whose source code is to be replaced.
count
Specifies the number of elements in the string and length arrays.
string
Specifies an array of pointers to strings containing the source code to be loaded into the shader.

Where the Shader we defined is only an empty object, say its code will be replaced? what is its code?

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.

[QUOTE=Betrayal;1264919]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.[/QUOTE]

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.

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.

[QUOTE=Alfonse Reinheart;1264930]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.[/QUOTE]

Questing is a kind of art, one can make it sense of it, one not, which has to be guessed by ansewers. after exchange times, they could understand each other.
I may not make it clearly at all, What I want to know is in this program, which statement described the roit of colors in the triangle? or which math formula in it describe the interpolation?
Is the interpolation processed in this example by linear or exponent? or other way of curves?
for examle, we draw a point by POINT()… what is it in the triangle to present the color?

There is only drawing statement: glDrawArrays(GL_TRIANGLES,0,3); //is it here?r
it draws a triangle, where is it linked with color?

[QUOTE=reader1;1264931]Questing is a kind of art, one can make it sense of it, one not, which has to be guessed by ansewers. after exchange times, they could understand each other.
I may not make it clearly at all, What I want to know is in this program, which statement described the roit of colors in the triangle? or which math formula in it describe the interpolation?
Is the interpolation processed in this example by linear or exponent? or other way of curves?
for examle, we draw a point by POINT()… what is it in the triangle to present the color?[/QUOTE]

No your questions are terrible. All of them.
It’s highly rude that you expect others to explain you every single bit of opengl, yet you are to lazy to read a book or even a wikipage. And please stop bumping your threads all the time!

Now so that this thread hopefully dies:
glDrawArrays is a drawing command, by that command the vertex attributes for positions and colors are pumped into the vertex shader, the vertex shader passes the color further to the fragment shader and in this step, colors get interpolated.

And now read a fucking book.

[QUOTE=Betrayal;1264933]No your questions are terrible. All of them.
It’s highly rude that you expect others to explain you every single bit of opengl, yet you are to lazy to read a book or even a wikipage. And please stop bumping your threads all the time!

Now so that this thread hopefully dies:
glDrawArrays is a drawing command, by that command the vertex attributes for positions and colors are pumped into the vertex shader, the vertex shader passes the color further to the fragment shader and in this step, colors get interpolated.

And now read a fucking book.[/QUOTE]

Couldn’t imagine why did yu reply like that? if you think its a shadow question, you can refuse to reply with a smile or do your things.
where is terrible? who will force you to explain one by one statement? can you point out? we know every process except the gradually changed color in the triangle.
you just recite or only copy book on the draw command. well, can you show what way the interpolation is? whcih arguments in the glDrawArrays(GL_TRIANGLES,0,3) represent the interpolation? How to change its interpolating distance?

Because your threads and questions are terrible and you told us in other threads that you don’t want to read given links, because it would take to much time for you and you’re simply to lazy. Instead you’re expecting that other people spend their time to help you.

Alfonse already gave you a link where your questions will be answered.

I highly doubt that. Regarding your threads you have no fucking idea whats going on and how things work in opengl. And you simply can’t learn all that things in a forum.

[QUOTE=reader1;1264935]
you just recite or only copy book on the draw command[/QUOTE]
No

FOLLOW THE LINK!

hm, I find an article to sove the problem.

[QUOTE=Betrayal;1264936]Because your threads and questions are terrible and you told us in other threads that you don’t want to read given links, because it would take to much time for you and you’re simply to lazy. Instead you’re expecting that other people spend their time to help you.

Alfonse already gave you a link where your questions will be answered.

I highly doubt that. Regarding your threads you have no fucking idea whats going on and how things work in opengl. And you simply can’t learn all that things in a forum.

No

FOLLOW THE LINK![/QUOTE]

so prompt to reply? sound like you have remembered every thread before.
your fuck idea must come from reciting the book with your fucking brain.
you would not be so fucking rude at the forum. if you don’t like to reply, you shut up.

Haven’t yet found any information on the gradient color produced in the simple sample from the doc and article. all of them seem not to discuss it deeply.

The color gradient is not produced by the shaders, it is part of the rasterization process.

The shader has some limited influence on the interpolation, it can choose between three interpolation modes: flat (no interpolation, the value of one vertex is used for the whole triangle), noperspective (the values are interpolated based on their screen position) and smooth (the values are interpolated based on their 3d-position).

If you didn’t specify an interpolation mode in your shaders, the default is smooth interpolation.