• Create Account

Banner advertising on our site currently available from just \$5!

### #Actualsap

Posted 06 August 2014 - 01:56 PM

Hello,

so using gl_VertexID we can create a fullscreen triangle without using any vertex buffer, index buffer or vertex array.

heres the code for the directx one:

out_texture = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
gl_Position = vec4(out_texture * vec2(2.0f, -2.0f) + vec2(-1.0f, 1.0f), 0.0f, 1.0f);


please ignore the fact that i used gl_Position instead of whatever they use in directx.

anyway, we can just draw 3 vertices (glDrawArrays(GL_TRIANGLES, 0, 3)) and the vertex shader for each vertex will create a vertex position and UV coord.

problem is, that vertex shader creates UV coords with [0,0] at top left instead of bottom left like opengl requires. so i think a change is needed when setting the gl_Position.

if i understand correctly this is what happens:

gl_VertexID = 0 makes out_texture = 0,0 and gl_Position = -1,1 (top left) and i want gl_Position = -1,-1 (bottom left)
gl_VertexID = 1 makes out_texture = 2,0 and gl_Position = 3,1 (top right) and i want gl_Position = 3,-1 (bottom right)
gl_VertexID = 2 makes out_texture = 0,2 and gl_Position = -1,-3 (bottom left) and i want gl_Position = -1,3 (top left)


google is full of search results showing the directx vertex shader, but i cant find a single one using opengl..

any help is welcome.

### #4sap

Posted 06 August 2014 - 01:54 PM

Hello,

so using gl_VertexID we can create a fullscreen triangle without using any vertex buffer, index buffer or vertex array.

heres the code for the directx one:

out_texture = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
gl_Position = vec4(out_texture * vec2(2.0f, -2.0f) + vec2(-1.0f, 1.0f), 0.0f, 1.0f);


please ignore the fact that i used gl_Position instead of whatever they use in directx.

anyway, we can just draw 3 vertices (glDrawArrays(GL_TRIANGLES, 0, 3)) and the vertex shader for each vertex will create a vertex position and UV coord.

problem is, that vertex shader creates UV coords with [0,0] at top left instead of bottom left like opengl requires. so i think a change is needed when setting the gl_Position.

if i understand correctly this is what happens:

gl_VertexID = 0 makes out_texture = 0,0 and gl_Position = -1,1 (top left) and i want gl_Position = -1,-1 (bottom left)
gl_VertexID = 1 makes out_texture = 2,0 and gl_Position = 3,1 (top right) and i want gl_Position = 3,-1 (bottom right)
gl_VertexID = 2 makes out_texture = 0,2 and gl_Position = -1,-3 (bottom left) and i want gl_Position = -1,3 (top left)


google is full of search results showing the directx vertex shader, but i cant find a single one using opengl..

any help is welcome.

### #3sap

Posted 06 August 2014 - 01:53 PM

Hello,

so using gl_VertexID we can create a fullscreen triangle without using any vertex buffer, index buffer or vertex array.

heres the code for the directx one:

out_texture = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
gl_Position = vec4(out_texture * vec2(2.0f, -2.0f) + vec2(-1.0f, 1.0f), 0.0f, 1.0f);


please ignore the fact that i used gl_Position instead of whatever they use in directx.

anyway, we can just draw 3 vertices (glDrawArrays(GL_TRIANGLES, 0, 3)) and the vertex shader for each vertex will create a vertex position and UV coord.

problem is, that vertex shader creates UV coords with [0,0] at top left instead of bottom left like opengl requires. so i think a change is needed when setting the gl_Position.

if i understand correctly this is what happens:

gl_VertexID = 0 makes out_texture = 0,0 and gl_Position = -1,1 (top left) and i want gl_Position = -1,-1 (bottom left)
gl_VertexID = 1 makes out_texture = 2,0 and gl_Position = 3,1 (top right) and i want gl_Position = 3,-1 (bottom right)
gl_VertexID = 2 makes out_texture = 0,2 and gl_Position = -1,-3 (bottom left) and i want gl_Position = -1,3 (top left)


google is full of search results showing the directx vertex shader, but i cant find a single one using opengl..

any help is welcome.

### #2sap

Posted 06 August 2014 - 01:53 PM

Hello,

so using gl_VertexID we can create a fullscreen triangle without using any vertex buffer, index buffer or vertex array.

heres the code for the directx one:

out_texture = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
gl_Position = vec4(out_texture * vec2(2.0f, -2.0f) + vec2(-1.0f, 1.0f), 0.0f, 1.0f);


please ignore the fact that i used gl_Position instead of whatever they use in directx.

anyway, we can just draw 3 vertices (glDrawArrays(GL_TRIANGLES, 0, 3)) and the vertex shader for each vertex will create a vertex position and UV coord.

problem is, that vertex shader creates UV coords with [0,0] at top left instead of bottom left like opengl requires. so i think a change is needed when setting the gl_Position.

if i understand correctly this is what happens:

gl_VertexID = 0 makes out_texture = 0,0 and gl_Position = -1,1 (top left) and i want gl_Position = -1,-1 (bottom left)
gl_VertexID = 1 makes out_texture = 2,0 and gl_Position = 3,1 (top right) and i want gl_Position = 3,-1 (bottom right)
gl_VertexID = 2 makes out_texture = 0,2 and gl_Position = -1,-3 (bottom left) and i want gl_Position = -1,3 (top left)


google is full of search results showing the directx vertex shader, but i cant find a single one using opengl..

any help is welcome.

### #1sap

Posted 06 August 2014 - 01:53 PM

Hello,

Hello,

so using gl_VertexID we can create a fullscreen triangle without using any vertex buffer, index buffer or vertex array.

heres the code for the directx one:

out_texture = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
gl_Position = vec4(out_texture * vec2(2.0f, -2.0f) + vec2(-1.0f, 1.0f), 0.0f, 1.0f);


please ignore the fact that i used gl_Position instead of whatever they use in directx.

anyway, we can just draw 3 vertices (glDrawArrays(GL_TRIANGLES, 0, 3)) and the vertex shader for each vertex will create a vertex position and UV coord.

problem is, that vertex shader creates UV coords with [0,0] at top left instead of bottom left like opengl requires. so i think a change is needed when setting the gl_Position.

if i understand correctly this is what happens:

gl_VertexID = 0 makes out_texture = 0,0 and gl_Position = -1,1 (top left) and i want gl_Position = -1,-1 (bottom left)
gl_VertexID = 1 makes out_texture = 2,0 and gl_Position = 3,1 (top right) and i want gl_Position = 3,-1 (bottom right)
gl_VertexID = 2 makes out_texture = 0,2 and gl_Position = -1,-3 (bottom left) and i want gl_Position = -1,3 (top left)


google is full of search results showing the directx vertex shader, but i cant find a single one using opengl..

any help is welcome.

PARTNERS