Jump to content
  • Advertisement
Sign in to follow this  

VAO/VBO and classes

This topic is 1437 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, everyone, need some help. I am really beginner with classes and programming at all so don't blame me biggrin.png
I have a class for creating and drawing VAO/VBO but it doesn't work. When i cut/paste all code from dat class into main.cpp it works fine but when i put it back to the class it draws nothing. What's amiss?



int main(int argc, char** argv)
SF_Display Display(1280, 720, "Viewport");
static const GLfloat triangle[] = { 0.0f, 0.5f, 0.0f, 0.5f, -0.5f, 0.0f, -0.5f, -0.5f, 0.0f };
SF_Mesh Mesh(triangle);
while (Display.SF_IsClosed())
Display.SF_Clear(0.0f, 0.1f, 0.3f, 1.0f);
return 0;



#include "sf_mesh.h"

SF_Mesh::SF_Mesh(static const GLfloat data[])
glGenVertexArrays(1, &sf_vertexArrayID);
glGenBuffers(1, &sf_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, sf_vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glDeleteVertexArrays(1, &sf_vertexArrayID);
void SF_Mesh::SF_Draw()
glDrawArrays(GL_TRIANGLES, 0, 3);



#ifndef SF_MESH_H

#define SF_MESH_H
class SF_Mesh
SF_Mesh(static const GLfloat data[]);
void SF_Draw();
GLuint sf_vertexBuffer;
GLuint sf_vertexArrayID;
Edited by Blackhardd

Share this post

Link to post
Share on other sites

It isn't supported in standard C++ to declare a function parameter as static. I'm somewhat surprised that even compiles.


The bigger issue, however, occurs when you attempt to take sizeof(data). That works fine when you try it in the main() function, since the compiler has access to the array definition. When you try it inside the SF_Mesh constructor, you only have access to an array parameter of unknown size, and sizeof(data) is returning the native size of a pointer (i.e. 4 bytes, when compiled for a 32-bit architecture).


Try either passing in the size of the array as a separate parameter, or using a std::vector instead.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!