Sorry to bring this thread back up. I’ve figured out that the projection problem on my wife’s laptop is probably related to the reuploading of data to the buffer.
Here’s the thread I started on that if you’re interested: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=306630#Post306630
But here’s the screenshots of what’s going on.
http://imgur.com/a/KpANE
I’ve narrowed it down to the problem in this thread because the scrambling never happens on the first maze, only on the second and subsequent ones.
So, what I’m doing is this:
every frame, I do a render
void Mazegen::render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Load the identity matrix (reset to the default position and orientation)
glLoadIdentity();
updateProjection();
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
renderMaze();
}
void Mazegen::renderMaze()
{
// Draw Walls and Paths
glDrawElements(GL_LINES, m_indices.size(), GL_UNSIGNED_INT, 0);
// Draw Player
glPointSize(4.0f);
if (!screenSaver) {
glDrawArrays(GL_POINTS, CurrCellVert, 1);
}
// Draw Start and End Cells
glPointSize(8.0f);
glDrawArrays(GL_POINTS, StartVert, 1);
glDrawArrays(GL_POINTS, EndVert, 1);
}
void Mazegen::updateProjection()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float screenAspect, mazeAspect, left, right, bottom, top;
screenAspect = (float) screenWidth / screenHeight;
mazeAspect = (float) (giCols+1) / (giRows+1);
left = 0;
right = 0;
bottom = 0;
top = 0;
if (screenAspect < 1.0) { //portrait
if (mazeAspect > screenAspect) { // tall maze
left = -1;
right = giCols+1;
bottom -= fabs((((((float) screenHeight * (giCols + 2)) / screenWidth) - giRows) / 2));
top = giRows + fabs((((((float) screenHeight * (giCols + 2)) / screenWidth) - giRows) / 2));
} else { // wide maze
left -= fabs((((((float) screenWidth * (giRows + 2)) / screenHeight) - giCols) / 2));
right = giCols + fabs((((((float) screenWidth * (giRows + 2)) / screenHeight) - giCols) / 2));
bottom = -1.0;
top = (giRows + 1);
}
} else { // landscape
if (mazeAspect < screenAspect) { // tall maze
left -= fabs((((((float) screenWidth * (giRows + 2)) / screenHeight) - giCols) / 2));
right = giCols + fabs((((((float) screenWidth * (giRows + 2)) / screenHeight) - giCols) / 2));
bottom = -1.0;
top = (giRows + 1);
} else { // wide maze
left = -1;
right = giCols+1;
bottom -= fabs((((((float) screenHeight * (giCols + 2)) / screenWidth) - giRows) / 2));
top = giRows + fabs((((((float) screenHeight * (giCols + 2)) / screenWidth) - giRows) / 2));
}
}
glOrtho(left, right, top, bottom, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
All of that is code that runs every frame when nothing has changed in my scene.
When I change my scene (And the first time the program runs) I have a function called initializeBuffers that basically does the following:
void Mazegen::initializeBuffers()
{
m_vertices.clear();
m_indices.clear();
m_colors.clear();
//A whole lot of vertex, index, and color push_back's occur here
}
And then the first time my program runs AFTER going through the initializeBuffers above, I do this:
void Mazegen::genBuffers()
{
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glGenBuffers(MAX_BUFFERS, &m_vbos[0]);
glBindBuffer(GL_ARRAY_BUFFER, m_vbos[VERTEX_BUFFER]); //Bind the vertex buffer
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * m_vertices.size(), &m_vertices[0], GL_DYNAMIC_DRAW); //Send the data to OpenGL
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vbos[INDEX_BUFFER]); //Bind the index buffer
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * m_indices.size(), &m_indices[0], GL_DYNAMIC_DRAW); //Send the data to OpenGL
glBindBuffer(GL_ARRAY_BUFFER, m_vbos[COLOR_BUFFER]);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * m_colors.size(), &m_colors[0], GL_DYNAMIC_DRAW); //Send the data to OpenGL
//Bind the color array, and set the color pointer to point at it
glBindBuffer(GL_ARRAY_BUFFER, m_vbos[COLOR_BUFFER]);
glColorPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_vbos[VERTEX_BUFFER]);
glVertexPointer(3, GL_FLOAT, 0, 0);
}
Which sets up my VBO’s for vertex, index, and color.
After the discussions we’ve had in this thread…If I need to change my scene, I do that, and then I run initializeBuffers above to populate the m_vertices, m_indices, and m_colors with new updated data, and instead of running the genBuffers function, I instead call the following:
void Mazegen::rebufferData()
{
glBindBuffer(GL_ARRAY_BUFFER, m_vbos[VERTEX_BUFFER]); //Bind the vertex buffer
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * m_vertices.size(), &m_vertices[0], GL_DYNAMIC_DRAW); //Send the new data to OpenGL
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vbos[INDEX_BUFFER]); //Bind the index buffer
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * m_indices.size(), &m_indices[0], GL_DYNAMIC_DRAW); //Send the new data to OpenGL
glBindBuffer(GL_ARRAY_BUFFER, m_vbos[COLOR_BUFFER]); //Bind the color buffer
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * m_colors.size(), &m_colors[0], GL_DYNAMIC_DRAW); //Send the data to OpenGL
}
and after that I go back to my render loop until it changes again.
This method is working apparently just fine on all of the workstations here at work. But my wife’s laptop isn’t handling the rebuffering so well. I must be missing something or doing something wrong. Any ideas given the code you see above?
rebufferData is the code that I need to run to replace the contents of the buffers with the now modified m_vertices, m_indices, and m_colors. Do I even need to be doing that or does the buffer’s already keep track of what’s in those vector arrays?