0

I'm trying to do a cross OpenGL ES - OpenGL 3.0 (not ES) code to draw triangles just changing the shaders being used.

The code works for the OpenGL ES version, but doesn't work for the OpenGL 3.0 one. Here is what I'm doing:

Vertex shader:

#version 330 core
in vec3 a_v4Position;
void main(){
gl_Position = vec4(a_v4Position, 1.0);
}

Fragment shader:

#version 330 core
out vec3 color;
void main(){
color = vec3(0,1,0);
}

Code to draw the triangle (GLProgram is linked correctly)

const float triangleVertices[] =
{
     0.0f,  0.5f, 0.0f,
    -0.5f, -0.5f, 0.0f,
     0.5f, -0.5f, 0.0f,
};

positionAttribLocation = glGetAttribLocation(GLProgram, "a_v4Position");
glEnableVertexAttribArray(positionAttribLocation);
glVertexAttribPointer(positionAttribLocation, 3, GL_FLOAT, GL_FALSE, 0, TriangleVertices);
glDrawArrays(GL_TRIANGLES, 0, 3);
SaintJob 2.0
  • 554
  • 4
  • 21
  • Can this actually be done? I thought the VertexAttribArray was associated with the VBO. Perhaps OpenGL ES is using a default VBO to be more resilient to incorrect code, but I think you are still using one implicitly. – zrbecker Jul 09 '15 at 19:53
  • Yes... I'm afraid of that too. I'm defining one VBO now in the ES version to check it out. – SaintJob 2.0 Jul 09 '15 at 19:54
  • If I am not mistaken, the VBO also needs a VAO, but it has been a while since I have played with OpenGL. – zrbecker Jul 09 '15 at 19:55
  • Using VBOs, the OpenGL ES version works but the OpenGL 3.0 still doesn't work. Maybe the VAOs are also needed as you say, but the VAOs are not needed in OpenGL ES I think. – SaintJob 2.0 Jul 09 '15 at 20:14
  • Both using client side vertex arrays and not using VAOs are marked as "legacy features" in ES 3.0, but still supported. For full OpenGL, they are not supported if you use a core profile context. Get rid of using those legacy features in ES, and you'll hit the intersection between the two. – Reto Koradi Jul 09 '15 at 20:31
  • 1
    So I must use VAOs for full OpenGL because I'm using a core profile context... – SaintJob 2.0 Jul 09 '15 at 20:35
  • @SaintJob2.0: Indeed. Core profiles require VAO + VBO – datenwolf Jul 09 '15 at 21:27
  • AFAIK the standard always requires a VAO but not all implementations enforce that. – orost Jul 09 '15 at 23:17
  • may be this could help [default attribute locations for fixed function pipeline in OpenGL 4.0++ core profile for nVidia gfx cards/drivers](http://stackoverflow.com/a/20574219/2521214) – Spektre Jul 10 '15 at 12:24

0 Answers0