I'm using openGL, and trying to draw a cube, but it won't show up. I used transform feedback and found out my vertex shader is outputting these values
[0] -0.500000000 float
[1] -0.500000000 float
[2] -3.54020095 float
[3] -4.50000000 float
[4] -0.500000000 float
[5] -0.500000000 float
[6] -4.55025101 float
[7] -5.50000000 float
[8] -0.500000000 float
[9] 0.500000000 float
[10] -3.54020095 float
[11] -4.50000000 float
[12] -0.500000000 float
[13] 0.500000000 float
[14] -3.54020095 float
[15] -4.50000000 float
[16] -0.500000000 float
[17] -0.500000000 float
[18] -4.55025101 float
[19] -5.50000000 float
[20] -0.500000000 float
[21] 0.500000000 float
[22] -4.55025101 float
[23] -5.50000000 float
[24] -0.500000000 float
[25] 0.500000000 float
[26] -3.54020095 float
[27] -4.50000000 float
[28] -0.500000000 float
[29] 0.500000000 float
[30] -4.55025101 float
[31] -5.50000000 float
[32] 0.500000000 float
[33] 0.500000000 float
[34] -3.54020095 float
[35] -4.50000000 float
[36] 0.500000000 float
[37] 0.500000000 float
[38] -3.54020095 float
[39] -4.50000000 float
[40] -0.500000000 float
[41] 0.500000000 float
[42] -4.55025101 float
[43] -5.50000000 float
[44] 0.500000000 float
[45] 0.500000000 float
[46] -4.55025101 float
[47] -5.50000000 float
[48] 0.500000000 float
[49] 0.500000000 float
[50] -3.54020095 float
[51] -4.50000000 float
[52] 0.500000000 float
[53] 0.500000000 float
[54] -4.55025101 float
[55] -5.50000000 float
[56] 0.500000000 float
[57] -0.500000000 float
[58] -3.54020095 float
[59] -4.50000000 float
[60] 0.500000000 float
[61] -0.500000000 float
[62] -3.54020095 float
[63] -4.50000000 float
[64] 0.500000000 float
[65] 0.500000000 float
[66] -4.55025101 float
[67] -5.50000000 float
[68] 0.500000000 float
[69] -0.500000000 float
[70] -4.55025101 float
[71] -5.50000000 float
[72] -0.500000000 float
[73] 0.500000000 float
[74] -3.54020095 float
[75] -4.50000000 float
[76] 0.500000000 float
[77] 0.500000000 float
[78] -3.54020095 float
[79] -4.50000000 float
[80] -0.500000000 float
[81] -0.500000000 float
[82] -3.54020095 float
[83] -4.50000000 float
[84] -0.500000000 float
[85] -0.500000000 float
[86] -3.54020095 float
[87] -4.50000000 float
[88] 0.500000000 float
[89] 0.500000000 float
[90] -3.54020095 float
[91] -4.50000000 float
[92] 0.500000000 float
[93] -0.500000000 float
[94] -3.54020095 float
[95] -4.50000000 float
[96] -0.500000000 float
[97] -0.500000000 float
[98] -3.54020095 float
[99] -4.50000000 float
[100] 0.500000000 float
[101] -0.500000000 float
[102] -3.54020095 float
[103] -4.50000000 float
[104] -0.500000000 float
[105] -0.500000000 float
[106] -4.55025101 float
[107] -5.50000000 float
[108] -0.500000000 float
[109] -0.500000000 float
[110] -4.55025101 float
[111] -5.50000000 float
[112] 0.500000000 float
[113] -0.500000000 float
[114] -3.54020095 float
[115] -4.50000000 float
[116] 0.500000000 float
[117] -0.500000000 float
[118] -4.55025101 float
[119] -5.50000000 float
[120] -0.500000000 float
[121] -0.500000000 float
[122] -4.55025101 float
[123] -5.50000000 float
[124] 0.500000000 float
[125] -0.500000000 float
[126] -4.55025101 float
[127] -5.50000000 float
[0] is an x, [1] is a y, [2] is a z, [3] is a w, [4] is the next vertex's x, etc. What is wrong with these values, because nothing is showing up?
If it helps, it works when I manually divide by w in the vertex shader.
Edit More details are:
My vertex shader is
#version 410 core
uniform mat4 View, Model, Project;
in vec4 vPosition;
out vec4 position;
void main(){
position=Project*Model*View*vPosition;
gl_Position=position;
}
out vec4 position is being transform fed back.
My fragment shader simply colors any fragments red.
The matrices are
model
1,0,0,0
0,1,0,0
0,0,1,0
0,0,0,1
view
1,0,0,0
0,1,0,0
0,0,1,5
0,0,0,1
projection
1,0,0,0
0,1,0,0
0,0,-1.01005030,1.00502515
0,0,-1,0
The vPositions are
const GLfloat cube_positions[] =
{
-.5f, -.5f, -.5f, 1.0f,
-.5f, -.5f, .5f, 1.0f,
-.5f, .5f, -.5f, 1.0f,
-.5f, .5f, .5f, 1.0f,
.5f, -.5f, -.5f, 1.0f,
.5f, -.5f, .5f, 1.0f,
.5f, .5f, -.5f, 1.0f,
.5f, .5f, .5f, 1.0f
};
Indexed by glDrawElements and these in the Element Array Buffer
const GLushort cube_indices[] =
{
0, 1, 2, 3, 6, 7, 4, 5,
0xFFFF,
2, 6, 0, 4, 1, 5, 3, 7
};
and 0xFFFF is the restart index
The range of values your vertex shader needs to output is [-1.0, 1.0] for the coordinates inside the view volume. This range is after the division by w
.
It looks like your coordinates are within this range. For example for the first vertex:
[0] -0.500000000 float
[1] -0.500000000 float
[2] -3.54020095 float
[3] -4.50000000 float
Applying the division by w
gives for x
, y
and z
coordinates:
0.11111
0.11111
0.78671
This vertex is within the view volume, as well as all the other coordinates.