Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualgboxentertainment

Posted 21 January 2013 - 07:23 AM

I am currently having trouble trying to create and load binary files of model vertex data into the vbo in OpenGL.

 

Here is the code for a simple test that I have done by writing 2D triangle data into a *.bin file:

 

	glm::vec2 points[6] =
	{
		glm::vec2( -0.5, -0.5 ), glm::vec2( 0.5, -0.5 ),
		glm::vec2( 0.5, 0.5 ), glm::vec2( 0.5, 0.5 ),
		glm::vec2( -0.5, 0.5 ), glm::vec2( -0.5, -0.5 )
	};
	
	std::ofstream fs("model.bin", std::ios::out | std::ios::binary | std::ios::app);
        for(int i = 0; i<6; i++)
	{
		fs.write((const char*)&points[i].x, sizeof(points[i].x));
		fs.write((const char*)&points[i].y, sizeof(points[i].y));
	}
	fs.close();

 

and here is the code for copying the data into the vbo:

 

	int length;
	char* data;
	ifstream is;
	is.open("model.bin", ios::binary);
	is.seekg(0, ios::end);
	length = is.tellg();
	is.seekg(0, ios::beg);
	data = new char[length];
	is.read(data, length);
	is.close();
 
	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);

 

 

All I am getting is a blank screen, instead of a large colored square at the centre of the window. What am I doing wrong?


#4gboxentertainment

Posted 21 January 2013 - 07:22 AM

I am currently having trouble trying to create and load binary files of model vertex data into the vbo in OpenGL.

 

Here is the code for a simple test that I have done by writing 2D triangle data into a *.bin file:

 

	glm::vec2 points[6] =
	{
		glm::vec2( -0.5, -0.5 ), glm::vec2( 0.5, -0.5 ),
		glm::vec2( 0.5, 0.5 ), glm::vec2( 0.5, 0.5 ),
		glm::vec2( -0.5, 0.5 ), glm::vec2( -0.5, -0.5 )
	};
	
	std::ofstream fs("model.bin", std::ios::out | std::ios::binary | std::ios::app);
        for(int i = 0; i<6; i++)
	{
		fs.write((const char*)&points[i].x, sizeof(points[i].x));
		fs.write((const char*)&points[i].y, sizeof(points[i].y));
	}
	fs.close();

 

and here is the rest of the code for initializing the vertex buffer:

 

GLuint vao, vbo;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
  1. int length;
  2. char* data;
  3. ifstream is;
  4. is.open("model.bin", ios::binary);
  5. is.seekg(0, ios::end);
  6. length = is.tellg();
  7. is.seekg(0, ios::beg);
  8. data = new char[length];
  9. is.read(data, length);
  10. is.close(); cout << "loading shaders.." << endl; glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW); GLuint program = InitShader("base_lighting.vs", "base_lighting.fs"); glUseProgram(program); GLuint loc = glGetAttribLocation(program, "vPosition"); glEnableVertexAttribArray(loc); glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, 0); glClearColor(0.0, 0.0, 0.0, 1.0);

 

 

All I am getting is a blank screen, instead of a large colored square at the centre of the window. What am I doing wrong?


#3gboxentertainment

Posted 21 January 2013 - 07:19 AM

I am currently having trouble trying to create and load binary files of model vertex data into the vbo in OpenGL.

 

Here is the code for a simple test that I have done by writing 2D triangle data into a *.bin file:

 

	glm::vec2 points[6] =
	{
		glm::vec2( -0.5, -0.5 ), glm::vec2( 0.5, -0.5 ),
		glm::vec2( 0.5, 0.5 ), glm::vec2( 0.5, 0.5 ),
		glm::vec2( -0.5, 0.5 ), glm::vec2( -0.5, -0.5 )
	};
	
	std::ofstream fs("model.bin", std::ios::out | std::ios::binary | std::ios::app);
        for(int i = 0; i<6; i++)
	{
		fs.write((const char*)&points[i].x, sizeof(points[i].x));
		fs.write((const char*)&points[i].y, sizeof(points[i].y));
	}
	fs.close();

 

and here is the rest of the code for initializing the vertex buffer:

 

GLuint vao, vbo;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

    FILE * f;
    f = fopen("model.bin", "r");

glm::vec2 data[6];
    int stbyte = sizeof(data);
    fseek(f, stbyte, SEEK_SET);
    fread(&data, sizeof(data), 1, f);

    memcpy(data, data, sizeof(data));

    fclose(f);

cout << "loading shaders.." << endl;

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);

GLuint program = InitShader("base_lighting.vs", "base_lighting.fs");
glUseProgram(program);

GLuint loc = glGetAttribLocation(program, "vPosition");
glEnableVertexAttribArray(loc);
glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, 0);

glClearColor(0.0, 0.0, 0.0, 1.0);

 

 

All I am getting is a blank screen, instead of a large colored square at the centre of the window. What am I doing wrong?


#2gboxentertainment

Posted 21 January 2013 - 07:18 AM

I am currently having trouble trying to create and load binary files of model vertex data into the vbo in OpenGL.

 

Here is the code for a simple test that I have done by writing 2D triangle data into a *.bin file:

 

	glm::vec2 points[6] =
	{
		glm::vec2( -0.5, -0.5 ), glm::vec2( 0.5, -0.5 ),
		glm::vec2( 0.5, 0.5 ), glm::vec2( 0.5, 0.5 ),
		glm::vec2( -0.5, 0.5 ), glm::vec2( -0.5, -0.5 )
	};
	
	std::ofstream fs("model.bin", std::ios::out | std::ios::binary | std::ios::app);
        for(int i = 0; i<6; i++)
	{
		fs.write((const char*)&points[i].x, sizeof(points[i].x));
		fs.write((const char*)&points[i].y, sizeof(points[i].y));
	}
	fs.close();

 

and here is the rest of the code for initializing the vertex buffer:

 

 


GLuint vao, vbo;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
 
    FILE * f;
    f = fopen("model.bin", "r");
 
glm::vec2 data[6];
    int stbyte = sizeof(data);
    fseek(f, stbyte, SEEK_SET);
    fread(&data, sizeof(data), 1, f);
 
    memcpy(data, data, sizeof(data));
 
    fclose(f);
 
cout << "loading shaders.." << endl;
 
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
 
GLuint program = InitShader("base_lighting.vs", "base_lighting.fs");
glUseProgram(program);
 
GLuint loc = glGetAttribLocation(program, "vPosition");
glEnableVertexAttribArray(loc);
glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
 
glClearColor(0.0, 0.0, 0.0, 1.0);

 

All I am getting is a blank screen, instead of a large colored square at the centre of the window. What am I doing wrong?


#1gboxentertainment

Posted 21 January 2013 - 07:18 AM

I am currently having trouble trying to create and load binary files of model vertex data into the vbo in OpenGL.

 

Here is the code for a simple test that I have done by writing 2D triangle data into a *.bin file:

 

	glm::vec2 points[6] =
	{
		glm::vec2( -0.5, -0.5 ), glm::vec2( 0.5, -0.5 ),
		glm::vec2( 0.5, 0.5 ), glm::vec2( 0.5, 0.5 ),
		glm::vec2( -0.5, 0.5 ), glm::vec2( -0.5, -0.5 )
	};
	
	std::ofstream fs("model.bin", std::ios::out | std::ios::binary | std::ios::app);
        for(int i = 0; i<6; i++)
	{
		fs.write((const char*)&points[i].x, sizeof(points[i].x));
		fs.write((const char*)&points[i].y, sizeof(points[i].y));
	}
	fs.close();

 

and here is the rest of the code for initializing the vertex buffer:

 

 


GLuint vao, vbo;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
 
    FILE * f;
    f = fopen("model.bin", "r");
 
glm::vec2 data[6];
    int stbyte = sizeof(data);
    fseek(f, stbyte, SEEK_SET);
    fread(&data, sizeof(data), 1, f);
 
    memcpy(data, data, sizeof(data));
 
    fclose(f);
 
cout << "loading shaders.." << endl;
 
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
 
GLuint program = InitShader("base_lighting.vs", "base_lighting.fs");
glUseProgram(program);
 
GLuint loc = glGetAttribLocation(program, "vPosition");
glEnableVertexAttribArray(loc);
glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
 
glClearColor(0.0, 0.0, 0.0, 1.0);

 

All I am getting is a blank screen, instead of a large colored square at the centre of the window. What am I doing wrong?

 


PARTNERS