Basic vertex shader binding & input

Hi, so I have been trying this for over a week before a post, any prods welcomed.
I’ve got a simple vertex shader, that feeds a frag shader, both shaders and source come from a qt example, I’m trying to port to OpenGL running on Windowz:


#version 330 core

attribute vec4 aPosition;                               
attribute vec2 aTexCoord;                               
uniform mat4 uModelViewProjectionMatrix;
varying vec2 vTexCoord;

void main() 
{
   // gl_Position — contains the position of the current vertex
   // the clip-space output position of the current vertex.
   gl_Position = uModelViewProjectionMatrix * aPosition;
   vTexCoord = aTexCoord;
}

And this is how I’m trying to feed it:


Init()
{
   m_expansion_shader = LoadShader(false, vertex_path.c_str(), pixel_path.c_str());
   if (!m_expansion_shader)
      return -1;

   glLinkProgram(m_expansion_shader);

   if (printProgramInfoLog(m_expansion_shader) == GL_FALSE)
   {
      glDeleteProgram(m_expansion_shader);
      return 0;
   }

   // Generate two slots for the vertex and color buffers
   GLuint _vao;
   // Generate and bind the vertex array object
   glGenVertexArrays(1, &_vao); CheckGLError();
   glBindVertexArray(_vao); CheckGLError();

   GLuint _vbo[2];
   // Generate two slots for the vertex and position buffers
   glGenBuffers(2, _vbo); CheckGLError();

   m_vertexPosition_location = glGetAttribLocation(m_expansion_shader, "aPosition"); CheckGLError();
   glEnableVertexAttribArray(m_vertexPosition_location); CheckGLError();
   glBindBuffer(GL_ARRAY_BUFFER, _vbo[0]); CheckGLError();
   glBufferData(GL_ARRAY_BUFFER, sizeof(m_v_array), m_v_array, GL_DYNAMIC_DRAW); CheckGLError();
   

   m_textureCoord_Location = glGetAttribLocation(m_expansion_shader, "aTexCoord"); CheckGLError();
   glEnableVertexAttribArray(m_textureCoord_Location); CheckGLError();
   glBindBuffer(GL_ARRAY_BUFFER, _vbo[1]); CheckGLError();
   glBufferData(GL_ARRAY_BUFFER, sizeof(m_tx_array), m_tx_array, GL_DYNAMIC_DRAW); CheckGLError();

   // Specify the location of the uniform variable
   m_uModelViewProjectionMatrix = glGetUniformLocation(m_expansion_shader, "uModelViewProjectionMatrix");CheckGLError();

   m_aspect_window = static_cast<GLfloat>(m_clientRect.right) / static_cast<GLfloat>(m_clientRect.bottom);
   glViewport(0, 0, m_clientRect.right, m_clientRect.bottom);
}

const GLfloat m_modelviewmatrix[] = {
   1.0f, 0.0f, 0.0f, 0.0f,
   0.0f, 1.0f, 0.0f, 0.0f,
   0.0f, 0.0f, 1.0f, 0.0f,
   0.0f, 0.0f, 0.0f, 1.0f
};

Draw()
{
      // Start using shader program to expand background image
      glUseProgram(m_expansion_shader); CheckGLError();
      // Lock the shared surface
      wglDXLockObjectsNV(m_hDX9Device, 1, &m_hGLSharedTexture); CheckGLError();
      
      glEnable(GL_TEXTURE_2D); CheckGLError();
      glActiveTexture(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D, m_GLTexture); CheckGLError();

      SetCurrentShaderParms(m_aspect_window, (float)m_src_w, (float)m_src_h); CheckGLError();

      /* From original qt shader application - set m_uModelViewProjectionMatrix - this is all wrong*/
      //const QSize sz = QSize(painter->device()->width() * aspect, painter->device()->height() * aspect);
      //QMatrix4x4 m;
      //m.ortho(0, sz.width(), sz.height(), 0, -999999, 999999); // ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane)
      //QnOpenGLRendererManager::instance(context)->setProjectionMatrix(m);
      //QnOpenGLRendererManager::instance(context)->setModelViewMatrix(QMatrix4x4(painter->deviceTransform()));
      //m_projectionMatrix is never changed - it is set to constant value :
      //m_modelViewMatrix // set depending on current screen size only.

      glUniformMatrix4fv(m_uModelViewProjectionMatrix, 1, GL_FALSE,/*m_projectionMatrix**/m_modelviewmatrix); CheckGLError();

      m_tx_array[0] = (float)0;
      m_tx_array[1] = (float)0;
      m_tx_array[2] = (float)m_src_w; //1280
      m_tx_array[3] = (float)0;
      m_tx_array[4] = (float)m_src_w; //1280
      m_tx_array[5] = (float)m_src_h; //1280
      m_tx_array[7] = (float)0;
      m_tx_array[8] = (float)m_src_h; //1280

      m_v_array[0] = (float)m_clientRect.left;
      m_v_array[1] = (float)m_clientRect.top;
      m_v_array[2] = (float)m_clientRect.right; // 1280
      m_v_array[3] = (float)m_clientRect.top;
      m_v_array[4] = (float)m_clientRect.right; // 1280
      m_v_array[5] = (float)m_clientRect.bottom; // 1280
      m_v_array[6] = (float)m_clientRect.left;
      m_v_array[7] = (float)m_clientRect.bottom; // 1280

   m_indices_for_render_quads[0] = 0;
   m_indices_for_render_quads[1] = 1;
   m_indices_for_render_quads[2] = 2;

   m_indices_for_render_quads[3] = 0;
   m_indices_for_render_quads[4] = 2;
   m_indices_for_render_quads[5] = 3;

     // glBindVertexArray(0); CheckGLError();

      glVertexAttribPointer(m_vertexPosition_location, VERTEX_POS_SIZE, GL_FLOAT, GL_FALSE, 0, m_v_array); CheckGLError();
      glVertexAttribPointer(m_textureCoord_Location, VERTEX_TEXCOORD0_SIZE, GL_FLOAT, GL_FALSE, 0, m_tx_array); CheckGLError();

      glEnableVertexAttribArray(m_vertexPosition_location);
      glEnableVertexAttribArray(m_textureCoord_Location);
      
      glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, m_indices_for_render_quads); CheckGLError();

      // Unlock the shared surface
      wglDXUnlockObjectsNV(m_hDX9Device, 1, &m_hGLSharedTexture); CheckGLError();
}

Full (attempt) source file: https://drive.google.com/open?id=1A7bVYyydZ7bn4ITS_VRdbjbbPFxVBFFN

Appreciated in advance, I can’t see any samples that match what I’m trying to achieve, I’m new to openGL unfortunately for me.
Sure there are some school boy errors.
Cheers.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.