Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 12 Oct 2011
Offline Last Active Jan 13 2015 05:20 PM

Topics I've Started

What if I have more models per level than available VBO memory?

05 July 2013 - 07:39 PM

I'm trying to understand more about how Vertex Buffer Objects work and how to best use them. I've run into a hypothetical situation that I can't find an answer to. Most tutorials are simple and don't cover complexity such as this. A lot of these questions probably stem from misunderstandings about VBOs.


If I have more models required in the current scene/level than I can create VBO data for, but not all are visible all the same time, how do I resolve the issue?


From my understanding of VBOs, they are expensive to build per frame, and are typically built when model data is loaded from the hard drive. From what I've seen in tutorials, every object needed in the scene/level is built into a VBO upon level initialization. While this works fine for simple tutorials, what if I have a huge level, or a world that needs to stream in real time from the hard drive? (Eg, Skyrim, Burnout Paradise, Just Cause 2, Far Cry 2 & 3)


Obliviously, I will need to create new VBOs at some point. But when? I can't change the VBO per frame without significant performance loss can I?


One solution I can think of is a grid system. Moving beyond the edge of a grid causes a rebuild of the current VBOs to match the new player area. While this works in the worst case, I feel that general usage won't produce very many worst case scenarios. Thus this would lead to unnecessary performance loss.


Would a Dynamic VBO be part of a solution? If so, wouldn't that mean I either have to combine all the objects into one VBO, or, carefully keep track of which VBOs I can reuse?

Keeping track of #includes?

27 February 2012 - 07:20 PM

So I've started writing my own project in C++. I was getting along quite well I thought, until I started to get compile errors with multiples of the same header files trying to be compiled. I took a closer look at my #include statements and came to a terrifying realization that it was a mess. A HUGE mess. I was amazed it had taken me that long to run into that error.

My question is; how do you keep track of your includes? What method works best? (eg. flow chart, string and bulletin board, white board, just a plain list....)

Also, what is the best way to create the hierarchy of includes, for example:

Lets say I have these files.
Bone, Mesh, Model, Entity, Manager, Updater, Main

Model relies on Mesh and Bone
Entity relies on Model
Manager relies on Mesh
Updater relies on Entity
Main relies on Manager, Updater.

What is the best way to include these files according to their individual dependencies?

I get stuck like this:
#include "Bone"
#include "Mesh"

#include "Model"

#include "Mesh"

#include "Entity"

What now? What do I include in Main? I need both Updater and Manager, but if I include both, I've included Mesh twice!?

I've got no strategy to contend with this. Any suggestions?

Fancy Windows Borders?

15 February 2012 - 02:09 PM

I'm trying to find more tutorials on general window creation, but specifically how to customize the border of the window. For example, Steam, Desura, and Chrome. These applications all have cool looking borders instead of the default Windows one. I've found many tutorials on how to show a window with the regular border, but I can't find any that go into customizing it. I don't really know what I should be searching google for either. Can someone point me in the right direction?

(Help)My matrices give me a blank screen!

21 December 2011 - 03:26 PM

I'm very new to C++ and OpenGL, and I've manage to cobble together a working bit of code from what I've learned from a bunch of OpenGL tutorials. And it works! Until I try and use any matrices to render in 3D. I don't think I'm doing anything wrong, and I'm pretty sure the matrices aren't filled with 0's. But I've hit a dead end and I don't know where to go, or what might be the problem. If you could help me I'd be very grateful. If you need some of the code I haven't posted, let me know.
(I'm using the GLM library for all the matrix stuff)

#include "opengl_4.h"
/-snipped-/ Creating of rendering context and whatnot

void OpenGLContext::setupScene(void) {
	glClearColor(0.3f,0.3f,0.3f,0.0f); //set the clear color to a dark grey
	shader = new Shader("basic.vert","basic.frag");
	item = new Object();

void OpenGLContext::reshapeWindow(int w, int h) {
	windowWidth = w; //Set the window width
	windowHeight = h; //Set thewindow height
	glViewport(0,0, windowWidth, windowHeight); //Set the viewport size to fill the window
	ProjectionMatrix = glm::perspective(
			(float)windowWidth / windowHeight,

void OpenGLContext::renderScene(void) {
	ModelViewMatrix = glm::mat4(1.0f);//glm::translate(glm::mat4(1.0f), glm::vec3(0.0f,0.0f, -5.0f));
	glUniformMatrix4fv(shader->locations[0], 1, GL_FALSE, &ProjectionMatrix[0][0]);
	glUniformMatrix4fv(shader->locations[1], 1, GL_FALSE, &ModelViewMatrix[0][0]);
	glDrawElements(GL_TRIANGLES, item->polyCount*3, GL_UNSIGNED_INT, (GLvoid*)0);
	SwapBuffers(hdc); //swap buffers so we can see our rendering

//Object file
#include "object.h"

void Object::makeDefaultObject()
	vert Vertices[4] = 
		{{ 0.0f, 0.5f, 0.0f, 1.0f},{0.0f,0.0f,1.0f,1.0f}},
		{{ 0.0f,-0.5f,-0.5f, 1.0f},{0.0f,1.0f,0.0f,1.0f}},
		{{ 0.5f,-0.5f, 0.5f, 1.0f},{1.0f,0.0f,0.0f,1.0f}},
		{{-0.5f,-0.5f, 0.5f, 1.0f},{1.0f,0.0f,0.0f,1.0f}}
	vertCount = 4;

	poly Polys[4] =
	polyCount = 4;

	glGenBuffers(1, &_vbo);
	glBindBuffer(GL_ARRAY_BUFFER, _vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glGenBuffers(1, &_ibo);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Polys), Polys, GL_STATIC_DRAW);

	glGenVertexArrays(1, &_vao);

	glBindBuffer(GL_ARRAY_BUFFER, _vbo);
	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertices[0]), 0);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertices[0]), (void*)sizeof(Vertices[0].position));
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);



void Object::bind()
void Object::unbind()

#include "shader.h"
#include <string.h>
#include <iostream>
#include <stdlib.h>

using namespace std;

static char* textFileRead(const char *fileName) {
	char* text = "NULL";
	if (fileName != NULL) {
        FILE *file = fopen(fileName, "rt");
		if (file != NULL) {
            fseek(file, 0, SEEK_END);
            int count = ftell(file);
			if (count > 0) {
				text = (char*)malloc(sizeof(char) * (count + 1));
				count = fread(text, sizeof(char), count, file);
				text[count] = '\0';
	return text;

Shader::Shader() {

Shader::Shader(const char *vsFile, const char *fsFile) {
    init(vsFile, fsFile);

void Shader::init(const char *vsFile, const char *fsFile) {
	shader_vp = glCreateShader(GL_VERTEX_SHADER);
	shader_fp = glCreateShader(GL_FRAGMENT_SHADER);
	const char* vsText = textFileRead(vsFile);
	const char* fsText = textFileRead(fsFile);	
    if (vsText == NULL || fsText == NULL) {
        cerr << "Either vertex shader or fragment shader file not found." << endl;
	glShaderSource(shader_vp, 1, &vsText, 0);
	glShaderSource(shader_fp, 1, &fsText, 0);
	shader_id = glCreateProgram();
	glAttachShader(shader_id, shader_fp);
	glAttachShader(shader_id, shader_vp);

	locations[0] = glGetUniformLocation(shader_id, "ProjMat");
	locations[1] = glGetUniformLocation(shader_id, "ModelViewMat");
	glBindAttribLocation(shader_id, 0, "in_Position"); //Bind a constant attribute location for positions of vertices
	glBindAttribLocation(shader_id, 1, "in_Color"); //Bind another constant attribute location, this time for color

Shader::~Shader() {
	glDetachShader(shader_id, shader_fp);
	glDetachShader(shader_id, shader_vp);

unsigned int Shader::id() {
	return shader_id;

void Shader::bind() {

void Shader::unbind() {

Vertex shader
#version 330

layout(location = 0) in vec4 in_Position;
layout(location = 1) in vec4 in_Colour;
out vec4 mid_Colour;

uniform in mat4 ProjMat;
uniform in mat4 ModelViewMat;

void main(void)
	gl_Position = ProjMat*ModelViewMat*in_Position;
	mid_Colour = in_Colour;
Fragment shader
#version 330

in vec4 mid_Colour;

out vec4 out_Color;

void main(void)
	out_Color = mid_Colour;

sorry about the huge page, I can't figure out how to shrink the code boxes.