glsl - Opengl 4.3 gl_VertexID not incrementing with glDrawArrays -


i'm having difficulty in understanding why gl_vertexid not incrementing each new vertex in code below rendering "debug text". hints/tips?

(original code referenced @ bottom of post)

hereafter vertex shader:

#version 430 core  layout( location = 0 ) in int character; out int vcharacter; out int vposition;  void main() {     vposition = gl_vertexid;     vcharacter = character;     gl_position = vec4(0, 0, 0, 1); } 

the geometry shader:

#version 430 core  layout(points) in; layout(triangle_strip, max_vertices = 4) out;  in int vcharacter[1]; in int vposition[1]; out vec2 gtexcoord; uniform sampler2d sampler;  uniform vec2 cellsize; uniform vec2 celloffset; uniform vec2 rendersize; uniform vec2 renderorigin;  void main() {     // determine final quad's position , size:     float x = renderorigin.x + float(vposition[0]) * rendersize.x * 2.0f;     float y = renderorigin.y;     vec4 p = vec4(x, y, 0, 1);     vec4 u = vec4(1, 0, 0, 0) * rendersize.x;     vec4 v = vec4(0, 1, 0, 0) * rendersize.y;      // determine texture coordinates:     int letter = vcharacter[0];     letter = clamp(letter - 32, 0, 96);     int row = letter / 16 + 1;     int col = letter % 16;     float s0 = celloffset.x + cellsize.x * col;     float t0 = celloffset.y + 1 - cellsize.y * row;     float s1 = s0 + cellsize.x - celloffset.x;     float t1 = t0 + cellsize.y;      // output quad's vertices:     gtexcoord = vec2(s0, t1); gl_position = p - u - v; emitvertex();     gtexcoord = vec2(s1, t1); gl_position = p + u - v; emitvertex();     gtexcoord = vec2(s0, t0); gl_position = p - u + v; emitvertex();     gtexcoord = vec2(s1, t0); gl_position = p + u + v; emitvertex();     endprimitive(); } 

the draw call , other relevant code:

glbindvertexarray(0); glbindbuffer(gl_array_buffer, 0); gluint attriblocation = glgetattriblocation(m_programtextprinter, "character"); glvertexattribipointer(attriblocation, 1, gl_unsigned_byte, 1, text.data()->c_str()); glenablevertexattribarray(attriblocation); gldrawarrays(gl_points, 0, text.data()->size()); 

basically code used text rendering. when use code, see letters put on top of each other. when modify

glvertexattribipointer(attriblocation, 1, gl_unsigned_byte, 1, text.data()->c_str()); 

into

glvertexattribipointer(attriblocation, 1, gl_unsigned_byte, 2, text.data()->c_str()); 

i notice there shift in x-direction expected geometry shader, nevertheless letters still on top of each other.

i'm using nvidia geforce gt 630m, driver version: 320.18 , opengl 4.3 context.

reference original author's code

i got code working using vbos bartek hinted at: replaced

glbindvertexarray(0); glbindbuffer(gl_array_buffer, 0); gluint attriblocation = glgetattriblocation(m_programtextprinter, "character"); glvertexattribipointer(attriblocation, 1, gl_unsigned_byte, 1, text.data()->c_str()); glenablevertexattribarray(attriblocation); gldrawarrays(gl_points, 0, text.data()->size()); 

with

gluint vaoid, bufferid; glgenvertexarrays(1, &vaoid); glbindvertexarray(vaoid); glgenbuffers(1, &bufferid); glbindbuffer(gl_array_buffer, bufferid); glbufferdata(gl_array_buffer, text.data()->size() * sizeof(gl_unsigned_byte), text.data()->data(), gl_dynamic_draw);  gluint attriblocation = glgetattriblocation(m_programtextprinter, "character"); glvertexattribipointer(attriblocation, 1, gl_unsigned_byte, 0, 0); glenablevertexattribarray(attriblocation);  gldrawarrays(gl_points, 0, text.data()->size());  gldeletevertexarrays(1, &vaoid); gldeletebuffers(1, &bufferid); 

Comments