Hello,
I'm a newbie to vertex shaders. I'm just trying to get my feet wet. I coded the following simple vertex shader:
[source lang="java"]const GLchar *shadersrc[] = { "void main()\n", "{\n", "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n", "}"};[/source]
I understand that gl_ModelViewProjectionMatrix may be deprecated, but I assume that if it's not working then the above code won't compile - which is not the case. So I assume that all's well.
I'm compiling/linking/using the shader with the following simple code:
[source lang="java"] nos = sizeof(shadersrc)/sizeof(char*); shad = glCreateShader (GL_VERTEX_SHADER); glShaderSource (shad,nos,shadersrc,NULL); glCompileShader (shad); glGetShaderiv (shad,GL_COMPILE_STATUS,&iflg); if(iflg == GL_TRUE) { printf("Shader successfully compiled\n"); } else { printf("Shader compilation failed\n"); return; } prog = glCreateProgram(); glAttachShader (prog,shad); glLinkProgram (prog); glUseProgram (prog);[/source]
I call glGetError() at this point and I get no error.
My understanding is that the above vertex shader should not change anything. However, if I use the above code nothing gets displayed.
Does anybody have a clue to what may be going on?
Thanks.
- Viewing Profile: Topics: amtri
Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics
Community Stats
- Group Members
- Active Posts 88
- Profile Views 658
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
146
Neutral
User Tools
Contacts
amtri hasn't added any contacts yet.
Topics I've Started
Simple vertex shader
03 August 2012 - 02:06 PM
CreateVertexBuffer vs SetFVF
20 June 2012 - 04:10 PM
Hello,
I need a clarification on the CreateVertexBuffer and the SetFVF functions.
The CreateVertexBuffer function takes as its 3rd argument a FVF value. The SetFVF function takes a FVF value as its single argument.
My question: do these always need to be the same? In other words, can I create a vertex buffer that allows for, say, XYZ coordinates, color, normals, and 2D textures, and yet call SetFVF with only XYZ coordinates and color?
I'm hoping the answer is "no", and that I'm able to use a single vertex buffer for multiple needs, using SetStreamSource to accomodate this. And, if that's the case, when I fill the buffer with only XYZ and color, do I pack the first 4 32-bit words with XYZ and color, or do I leave space for the normals as the vertex buffer was created with enough room for it?
Thanks.
I need a clarification on the CreateVertexBuffer and the SetFVF functions.
The CreateVertexBuffer function takes as its 3rd argument a FVF value. The SetFVF function takes a FVF value as its single argument.
My question: do these always need to be the same? In other words, can I create a vertex buffer that allows for, say, XYZ coordinates, color, normals, and 2D textures, and yet call SetFVF with only XYZ coordinates and color?
I'm hoping the answer is "no", and that I'm able to use a single vertex buffer for multiple needs, using SetStreamSource to accomodate this. And, if that's the case, when I fill the buffer with only XYZ and color, do I pack the first 4 32-bit words with XYZ and color, or do I leave space for the normals as the vertex buffer was created with enough room for it?
Thanks.
Debugging Direct3D9 - no image
20 June 2012 - 12:08 PM
Hello,
I'm having some basic problems with Direct3D9 and I'm hoping somebody can point me in the right direction. I have succeeded in using Direct3D in the past, but I had separate vertex buffers for each primitive. I would then fill the vertex buffer, then call a DrawPrimitive a single time. It all worked fine.
Now I have the following sequence:
1) Create a vertex buffer
2) Add one triangle to the buffer. At this point, I call
Lock(0,0,&bfr,D3DLOCK_DISCARD)
copy triangle vertex data into bfr, starting at bfr[0]
3) Add second triangle to the buffer. Here I assume I do not need to call Lock again as I have bfr saved. I simply copy the triangle vertex into bfr, starting at bfr[3] ("3" means I have the stride into consideration).
4) Now I'm going to draw. I do
BeginScene
SetFVF
SetStreamSource(0,VB,0,size);
DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
5) Now the second triangle. Since BeginScene and SetFVF have already been called I now call
SetStreamSource(0,VB,0,size); (again)
DrawPrimitive(D3DPT_TRIANGLELIST,3,1);
6) Finally, I do
EndScene
Present
The image I get is completely wrong. So my questions:
(a) Is there a way to debug Direct3D9 so I can actually see what it's trying to do and why it displayed the image it did?
(b) Am I doing something obviously wrong above?
© I will keep the vertex buffer for a while as I rotate the model. This means that the drawing part gets repeated many times, while copying the data to the buffer is done once only. Once I'm done with viewing this I will Release the vertex buffer altogether. In other words, I will write to the "bfr" pointer many times, while Lock has been called only once. Am I using the right options in the functions above?
(d) I tried using the DirectX Control Panel where I choose to use the Debug version of Direct3D. Should I expect to see any output anywhere in Visual Studio - or anywhere else, for that matter?
Thanks.
I'm having some basic problems with Direct3D9 and I'm hoping somebody can point me in the right direction. I have succeeded in using Direct3D in the past, but I had separate vertex buffers for each primitive. I would then fill the vertex buffer, then call a DrawPrimitive a single time. It all worked fine.
Now I have the following sequence:
1) Create a vertex buffer
2) Add one triangle to the buffer. At this point, I call
Lock(0,0,&bfr,D3DLOCK_DISCARD)
copy triangle vertex data into bfr, starting at bfr[0]
3) Add second triangle to the buffer. Here I assume I do not need to call Lock again as I have bfr saved. I simply copy the triangle vertex into bfr, starting at bfr[3] ("3" means I have the stride into consideration).
4) Now I'm going to draw. I do
BeginScene
SetFVF
SetStreamSource(0,VB,0,size);
DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
5) Now the second triangle. Since BeginScene and SetFVF have already been called I now call
SetStreamSource(0,VB,0,size); (again)
DrawPrimitive(D3DPT_TRIANGLELIST,3,1);
6) Finally, I do
EndScene
Present
The image I get is completely wrong. So my questions:
(a) Is there a way to debug Direct3D9 so I can actually see what it's trying to do and why it displayed the image it did?
(b) Am I doing something obviously wrong above?
© I will keep the vertex buffer for a while as I rotate the model. This means that the drawing part gets repeated many times, while copying the data to the buffer is done once only. Once I'm done with viewing this I will Release the vertex buffer altogether. In other words, I will write to the "bfr" pointer many times, while Lock has been called only once. Am I using the right options in the functions above?
(d) I tried using the DirectX Control Panel where I choose to use the Debug version of Direct3D. Should I expect to see any output anywhere in Visual Studio - or anywhere else, for that matter?
Thanks.
Using VBOs with multiple glDrawArrays
21 May 2012 - 01:06 PM
Hello,
I'm trying to use VBOs but realized the theory is not quite clear to me. I was hoping somebody could answer a few basic questions. As an example, suppose I want to draw 2 triangles: on the first I want to enable the coordinates and the colors; on the second I want to enable the coordinates, textures, and normals.
My thought was to pack everything into a single buffer large enough to contain all data. The coordinates, texture coordinates, normals, and colors are all in separate arrays. Since the two triangles do not use the same information, my coordinates array contains xyz for 6 points; my colors array contains rgb for 3 points; the normals array also contains information for 3 points; and the texture coordinates also contains information for 3 points.
The "stride" in all calls to glXXXPointer is set to zero as coordinates, normals, etc. are all packed.
1) Do I need to assume that all vertices share all attributes - i.e., coordinates, normals, textures, etc, as far a copying data to the VBO with, say, glBufferSubData?
2) My plan is to call glDrawArrays twice: once for first triangle and once for the second triangle. But the glDrawArrays function requires a starting point. Does this mean I have to "make room" in the VBO for coordinates, colors, normals, and textures for ALL points in the model, even if they won't ever be referenced (because, say, texcoord won't be enabled when drawing the first triangle)?
3) Of course, my model is much more complicated than just 2 triangles - I usually have on the order of about 1M geometric primitives, with all types of combinations for normals, textures, colors, etc. Sometimes some are on, and sometimes they are off. I would like to copy all my data to the VBO so I can quickly rotate the model that is already in the GPU. I'm just not clear whether I have to make a worst-case scenario assumption that all vertices always have all attributes.
4) I could also have separate buffers for each attribute: one buffer for coordinates; one for textures; one for color, etc. But if I have textures on a single triangle out of 1M triangles, would this mean I have to assume that all triangles have textures so that glDrawArrays can find the texture properly?
I hope I made my problem clear. If somebody could clear this for me I would appreciate it.
Thanks!
I'm trying to use VBOs but realized the theory is not quite clear to me. I was hoping somebody could answer a few basic questions. As an example, suppose I want to draw 2 triangles: on the first I want to enable the coordinates and the colors; on the second I want to enable the coordinates, textures, and normals.
My thought was to pack everything into a single buffer large enough to contain all data. The coordinates, texture coordinates, normals, and colors are all in separate arrays. Since the two triangles do not use the same information, my coordinates array contains xyz for 6 points; my colors array contains rgb for 3 points; the normals array also contains information for 3 points; and the texture coordinates also contains information for 3 points.
The "stride" in all calls to glXXXPointer is set to zero as coordinates, normals, etc. are all packed.
1) Do I need to assume that all vertices share all attributes - i.e., coordinates, normals, textures, etc, as far a copying data to the VBO with, say, glBufferSubData?
2) My plan is to call glDrawArrays twice: once for first triangle and once for the second triangle. But the glDrawArrays function requires a starting point. Does this mean I have to "make room" in the VBO for coordinates, colors, normals, and textures for ALL points in the model, even if they won't ever be referenced (because, say, texcoord won't be enabled when drawing the first triangle)?
3) Of course, my model is much more complicated than just 2 triangles - I usually have on the order of about 1M geometric primitives, with all types of combinations for normals, textures, colors, etc. Sometimes some are on, and sometimes they are off. I would like to copy all my data to the VBO so I can quickly rotate the model that is already in the GPU. I'm just not clear whether I have to make a worst-case scenario assumption that all vertices always have all attributes.
4) I could also have separate buffers for each attribute: one buffer for coordinates; one for textures; one for color, etc. But if I have textures on a single triangle out of 1M triangles, would this mean I have to assume that all triangles have textures so that glDrawArrays can find the texture properly?
I hope I made my problem clear. If somebody could clear this for me I would appreciate it.
Thanks!
glVertexPointer and glColor4fv
25 April 2012 - 11:36 AM
Hello,
I am using glVertexPointer to set my point coordinates. The only primitives I have are triangles. I could use glColorPointer, but all triangles - possibly millions - are the same color. So rather than using glColorPointer I would like to use glColor(3,4).
If I use glColor3f, this works just fine on my machine. However, if I use glColor4f and the transparency value is set, the resulting triangles are NOT transparent.
I'm wondering...:
1) Is it legal to enable VertexPointer but NOT ColorPointer? In other words, am I just lucky that the call to glColor3f on my machine worked when the true behavior when pointers are being used is undefined?
2) If this is legal - as I hope it is - is there anything special that needs to be done to make glColor4f work to get transparency? Or is this the result of a probable bug in my code?
The code is rather large and I cannot post it here. So I thought I'd just ask about the rules to make sure I'm using them correctly.
Thanks.
I am using glVertexPointer to set my point coordinates. The only primitives I have are triangles. I could use glColorPointer, but all triangles - possibly millions - are the same color. So rather than using glColorPointer I would like to use glColor(3,4).
If I use glColor3f, this works just fine on my machine. However, if I use glColor4f and the transparency value is set, the resulting triangles are NOT transparent.
I'm wondering...:
1) Is it legal to enable VertexPointer but NOT ColorPointer? In other words, am I just lucky that the call to glColor3f on my machine worked when the true behavior when pointers are being used is undefined?
2) If this is legal - as I hope it is - is there anything special that needs to be done to make glColor4f work to get transparency? Or is this the result of a probable bug in my code?
The code is rather large and I cannot post it here. So I thought I'd just ask about the rules to make sure I'm using them correctly.
Thanks.
- Home
- Viewing Profile: Topics: amtri