PDA

View Full Version : Where is shading statement?



reader1
03-15-2015, 09:39 AM
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 )

Alfonse Reinheart
03-15-2015, 10:12 AM
Have you considered reading some learning material about OpenGL (https://www.opengl.org/wiki/Getting_Started#Tutorials_and_How_To_Guides), 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.

reader1
03-15-2015, 10:26 PM
Have you considered reading some learning material about OpenGL (https://www.opengl.org/wiki/Getting_Started#Tutorials_and_How_To_Guides), 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?

reader1
03-16-2015, 12:18 AM
well, from draw begin.

Dark Photon
03-16-2015, 06:46 AM
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 ... or
... blocks.

reader1
03-16-2015, 09:01 AM
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;
}

reader1
03-16-2015, 09:09 AM
glDrawArrays() shows a colorful triangle, but it has only three sest of vertex and color, where the triangle got a gradual shading color?

Betrayal
03-16-2015, 11:15 AM
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.

reader1
03-16-2015, 08:32 PM
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.

Alfonse Reinheart
03-16-2015, 11:08 PM
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" (https://www.opengl.org/wiki_132/index.php?title=Special%3ASearch&profile=default&search=Interpolation&fulltext=Search) 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.

reader1
03-17-2015, 01:01 AM
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" (https://www.opengl.org/wiki_132/index.php?title=Special%3ASearch&profile=default&search=Interpolation&fulltext=Search) 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.

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?

reader1
03-17-2015, 01:29 AM
There is only drawing statement: glDrawArrays(GL_TRIANGLES,0,3); //is it here?r
it draws a triangle, where is it linked with color?

Betrayal
03-17-2015, 02:25 AM
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?

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.

reader1
03-17-2015, 03:53 AM
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.

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?

Betrayal
03-17-2015, 04:53 AM
Couldn't imagine why did yu reply like that?

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.



we know every process except the gradually changed color in the triangle.

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.



you just recite or only copy book on the draw command
No



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?

FOLLOW THE LINK!

reader1
03-17-2015, 05:04 AM
hm, I find an article to sove the problem.

reader1
03-17-2015, 05:16 AM
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!

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.

reader1
03-18-2015, 09:33 PM
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.

mbentrup
03-19-2015, 04:22 AM
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.

reader1
03-19-2015, 08:34 PM
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.
If you didn't specify an interpolation mode in your shaders, the default is smooth interpolation
Thank you, that's what I expected! most texts say only if you don't specify shaders, the glsl will use their default inner shader, which can implement smooth interpolation and other operations like shift, transformation.......
but here we specify a simple shader, in which there is a gl_fragcolor output. then we can fond no interpolation operation. That is our question. now yours is answer.