PDA

View Full Version : Having troubles drawing more than one VBO



nakedman
10-17-2011, 04:40 PM
Hi,

I have two object (C++ classes) with each a working VBO. That is, if I initialize both classes and just draw one of them, it works fine. But if I try to draw them both, only the first one gets drawn - and no errors occurs either.

My main loop is:


do {
particles.Draw();
ifs.Draw();
Music::Instance()->Update();
screen.Update();
} while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
glfwGetWindowParam( GLFW_OPENED ) );


and my classes are here

particles:




#include "Particles.h"

Particles::Particles() {
// Initialize stuff here
h = Hilfer();
amount = 500;
voidOffset = amount*16;
h.seed(5);

for(int i = 0; i < amount; i++) {
data.push_back(h.randomPosition());
data.push_back(h.randomPosition());
data.push_back(h.randomPosition());
data.push_back(1.0f);
}

for(int i = 0; i < amount; i++) {
data.push_back(h.randomColor());
data.push_back(h.randomColor());
data.push_back(h.randomColor());
data.push_back(1.0f);
}
float* vertexData = &amp;data[0];
std::cout << sizeof(vertexData) << std::endl;
int SizeOfData = sizeof(float)*amount*8;

shaderList.push_back(shader.LoadShader(GL_VERTEX_S HADER, "particles.vert"));
shaderList.push_back(shader.LoadShader(GL_FRAGMENT _SHADER, "particles.frag"));

theProgram = shader.CreateProgram(shaderList);

//glGenVertexArrays(1, &amp;vao);
//glBindVertexArray(vao);
glGenBuffers(1, &amp;vertexBufferObject);

glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, SizeOfData, vertexData, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

offsetLocation = glGetUniformLocation(theProgram, "offset");
fXOffset = 0.0f, fYOffset = 0.2f;
//glBindVertexArray(0);
if(glewIsSupported("GL_ARB_point_sprite GL_ARB_point_parameters")) {
std::cout << "Point sprites are supported." << std::endl;
} else {
std::cout << "Point sprites are NOT supported." << std::endl;
}

}

Particles::~Particles() {
// Kill stuff here

}

void Particles::Draw() {
Refresh();
}

void Particles::Refresh() {

glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE);
glEnable(GL_POINT_SPRITE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_PROGRAM_POINT_SIZE);
fXOffset+=0.01f;
if(fXOffset>30.0f) {
fXOffset-=30.0f;
}
glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);

glUseProgram(theProgram);
glUniform2f(offsetLocation, fXOffset, fYOffset);
glPointSize(3.5f);


//glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);

glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);

glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*)voidOffset);

glDrawArrays(GL_POINTS, 0, amount);

glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);


glBindBuffer(GL_ARRAY_BUFFER, 0);
//glBindVertexArray(0);
glUseProgram(0);

glDisable(GL_BLEND);
glDisable(GL_PROGRAM_POINT_SIZE);
glDisable(GL_POINT_SPRITE);
glEnable(GL_DEPTH_TEST);
h.checkGLError();
}


and my ifs



#include "IFS.h"

IFS::IFS() {
// Initialize stuff here
lastPressed = glfwGetTime();
h = Hilfer();
amount = 4500;
voidOffset = amount*16;
h.seed(5);
//Initiate data

// h.random() is 0.0f -> 1.0f;

//Change this from vec4 + vec4 to 8*vec1's
for(int i = 0; i < amount; i++) {
data.push_back(float(i)/float(10000));
}

float* vertexData = &amp;data[0];
std::cout << sizeof(vertexData) << std::endl;
int SizeOfData = sizeof(float)*amount;
std::cout << "SizeOfData = " << SizeOfData << std::endl;

shaderList.push_back(shader.LoadShader(GL_VERTEX_S HADER, "IFS.vert"));
shaderList.push_back(shader.LoadShader(GL_FRAGMENT _SHADER, "IFS.frag"));


theProgram = shader.CreateProgram(shaderList);

//glGenVertexArrays(1, &amp;vao);
//glBindVertexArray(vao);

glGenBuffers(1, &amp;vertexBufferObject);

glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, SizeOfData, vertexData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

offsetLocation = glGetUniformLocation(theProgram, "offset");
//texture_shader = glGetUniformLocation(theProgram, "tex");
fXOffset = 0.3f, fYOffset = 0.5f;
time = glfwGetTime();
uniformUsed = 0;
wheelPos = 0;
//glBindVertexArray(0);
}

bool IFS::LoadTexture() {
Bitmap *image;
image=new Bitmap();

if(image==NULL) {
return false;
}

if (image->loadBMP("pal.bmp")) {

glGenTextures(1, &amp;tex);

glBindTexture(GL_TEXTURE_1D, tex);

glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);

glTexImage1D(GL_TEXTURE_1D, 0, 3, image->width, 0,
GL_RGB, GL_UNSIGNED_BYTE, image->data);

}
else {
return false;
}

if (image) {
delete image;
}

return true;
}

IFS::~IFS() {
// Kill stuff here


}

void IFS::Draw() {
Refresh();
}

void IFS::Refresh() {



glUseProgram(theProgram);
glUniform2f(offsetLocation, fXOffset, fYOffset);


fXOffset += 0.001f;
//glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);

glEnableVertexAttribArray(0);
//glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
//glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*)voidOffset);
glPointSize(2.5f);
glDrawArrays(GL_POINTS, 0, amount);

glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
//glBindVertexArray(0);

//glDisableVertexAttribArray(1);
glUseProgram(0);

h.checkGLError();
}


I upped them to codepad as well, if that's easier to read:
IFS: http://codepad.org/e362eTiH
Particles: http://codepad.org/MPmZTOZe

I hope you can spot the error - thanks