Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: vao invalid use - problems with vertex array

  1. #1
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    5

    vao invalid use - problems with vertex array

    This is a part of code from tutorial:

    Code :
    //Copyright (C) 2010-2012 by Jason L. McKesson
    //This file is licensed under the MIT License.
     
     
    #include <string>
    #include <vector>
    #include <stack>
    #include <math.h>
    #include <stdio.h>
    #include <glload/gl_3_3.h>
    #include <glutil/glutil.h>
    #include <GL/freeglut.h>
    #include "../framework/framework.h"
    #include "../framework/Mesh.h"
    #include <glm/glm.hpp>
    #include <glm/gtc/type_ptr.hpp>
    #include <glload/gl_3_2_comp.h>
    #include <algorithm>
     
    #define ARRAY_COUNT( array ) (sizeof( array ) / (sizeof( array[0] ) * (sizeof( array ) != sizeof(void*) || sizeof( array[0] ) <= sizeof(void*))))
     
    struct ProgramData
    {
    	static GLuint theProgram;
    	GLuint modelToWorldMatrixUnif;
    	GLuint worldToCameraMatrixUnif;
    	GLuint cameraToClipMatrixUnif;
    	GLuint baseColorUnif;
    };
     
    float g_fzNear = 1.0f;
    float g_fzFar = 1000.0f;
     
    ProgramData UniformColor;
    ProgramData ObjectColor;
    ProgramData UniformColorTint;
     
    ProgramData LoadProgram(const std::string &strVertexShader, const std::string &strFragmentShader)
    {
    	std::vector<GLuint> shaderList;
     
    	shaderList.push_back(Framework::LoadShader(GL_VERTEX_SHADER, strVertexShader));
    	shaderList.push_back(Framework::LoadShader(GL_FRAGMENT_SHADER, strFragmentShader));
     
    	ProgramData data;
    	data.theProgram = Framework::CreateProgram(shaderList);
    	data.modelToWorldMatrixUnif = glGetUniformLocation(data.theProgram, "modelToWorldMatrix");
    	data.worldToCameraMatrixUnif = glGetUniformLocation(data.theProgram, "worldToCameraMatrix");
    	data.cameraToClipMatrixUnif = glGetUniformLocation(data.theProgram, "cameraToClipMatrix");
    	data.baseColorUnif = glGetUniformLocation(data.theProgram, "baseColor");
     
    	return data;
    }
     
    void InitializeProgram()
    {
    	UniformColor = LoadProgram("PosOnlyWorldTransform.vert", "ColorUniform.frag");
    	ObjectColor = LoadProgram("PosColorWorldTransform.vert", "ColorPassthrough.frag");
    	UniformColorTint = LoadProgram("PosColorWorldTransform.vert", "ColorMultUniform.frag");
    }
     
    Framework::Mesh *g_pConeMesh = NULL;
    Framework::Mesh *g_pCylinderMesh = NULL;
    Framework::Mesh *g_pCubeTintMesh = NULL;
    Framework::Mesh *g_pCubeColorMesh = NULL;
    Framework::Mesh *g_pPlaneMesh = NULL;
     
    const float vertex[]={0, 1, 0, 1.0f,
    -0.433913f, 0.900955f, 0, 1.0f,
    -0.781844f, 0.623474f, 0, 1.0f,
    -0.974929f, 0.222514f, 0, 1.0f,
    -0.974929f, -0.222514f, 0, 1.0f,
    -0.781844f, -0.623474f, 0, 1.0f,
    -0.433913f, -0.900955f, 0, 1.0f,
    0, -1, 0, 1.0f};
     
    GLubyte indices[]={1,4,6,54,3,4,5,7,78,5,4,2,4,6};
     
    GLuint positionBufferObject;
    GLuint vao;
     
    void InitializeVertexBuffer()
    {
    	glGenBuffers(1, &positionBufferObject);
     
    	glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
    	glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW);
    	glBindBuffer(GL_ARRAY_BUFFER, 0);
    }
     
     
    void init()
    {
    	InitializeProgram();
     
    	try
    	{
    		g_pConeMesh = new Framework::Mesh("UnitConeTint.xml");
    		g_pCylinderMesh = new Framework::Mesh("UnitCylinderTint.xml");
    		g_pCubeTintMesh = new Framework::Mesh("UnitCubeTint.xml");
    		g_pCubeColorMesh = new Framework::Mesh("UnitCubeColor.xml");
    		g_pPlaneMesh = new Framework::Mesh("UnitPlane.xml");
    	}
    	catch(std::exception &except)
    	{
    		printf("%s\n", except.what());
    		throw;
    	}
     
    	glEnable(GL_CULL_FACE);
    	glCullFace(GL_BACK);
    	glFrontFace(GL_CW);
     
    	glEnable(GL_DEPTH_TEST);
    	glDepthMask(GL_TRUE);
    	glDepthFunc(GL_LEQUAL);
    	glDepthRange(0.0f, 1.0f);
    	glEnable(GL_DEPTH_CLAMP);
     
    	InitializeVertexBuffer();
    	glGenVertexArrays(1, &vao);
    	glBindVertexArray(vao);
    }
     
    void display()
    {
    	glUseProgram(ProgramData::theProgram);
     
    	glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
    	glEnableVertexAttribArray(0);
    	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
     
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
     
    	glutil::PushStack push(modelMatrix);
    	modelMatrix.Scale(glm::vec3(100.0f, 100.0f, 100.0f));
    	glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices);
    	glutPostRedisplay();
    	}
     
    	glutSwapBuffers();
    }

    I modified original file, adding vertex buffers, but after running program I get error about invalid use of VAO/VBO/pointer, although it is exactly the same what is working properly in another file. Where is mistake?

    • I have vao declared
    • I have buffers generated and binded
    • I have array of vertices


    Here are many other errors because I removed parts of code which are not important for a problem. I only need to know what is wrong with vao.

    Thanks for answers.
    Last edited by chromosom; 06-01-2014 at 06:43 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •