/* Compile with : g++ vbo_stride_fail.cpp -g -lglfw -lGL -lGLEW -lGLU -o vbo_fail */ #include #include #include #include #include struct Vector3 { Vector3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {} union { struct { float x, y, z; }; struct { float xyz[3]; }; }; }; struct Color { Color(unsigned char _r, unsigned char _g, unsigned char _b) : r(_r), g(_g), b(_b) {} union { struct { unsigned char r,g,b; }; struct { unsigned char rgb[3];}; }; }; #define VERTEX_COUNT 3 struct Vector3 pos[VERTEX_COUNT] = { Vector3(-1, -1, 0), Vector3(-1, 1, 0), Vector3(1, 1, 0) }; struct Color col[VERTEX_COUNT] = { Color(255, 0,0), Color(0, 255, 0), Color(0, 0, 255) }; int copyVec3(const Vector3& data, unsigned char* out) { float* fout = (float*) out; *fout++ = data.x; *fout++ = data.y; *fout++ = data.z; return sizeof(data); } int copyColor(const Color& data, unsigned char* fout) { *fout++ = data.r; *fout++ = data.g; *fout++ = data.b; return sizeof(data); } int fillVboBuffer(unsigned char** buffer, unsigned int** indices, int& outSizePerEntry) { outSizePerEntry = 0; outSizePerEntry += sizeof(Vector3); // position outSizePerEntry += 3 * sizeof(char); // color (*buffer) = new unsigned char[outSizePerEntry * VERTEX_COUNT]; (*indices) = new unsigned int[outSizePerEntry]; int index = 0; for(int i=0; i