• Advertisement
Sign in to follow this  

VBO crashes *solved

This topic is 4149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

well ive had this problem for a while.. last time i just simply switched over to display lists but i cant do taht in this case... my problem is that the program crashes as soon as i call "DrawElements" to render the VBO... why is that?

#include "Terrain.h"
#ifndef Terrain_H
#define Terrain_H

class CTERRAIN
{
	public:			

		CTERRAIN();

		virtual ~CTERRAIN(void);

		void Render();

		void InitVertexBuffer(int Width, int Height);
		void InitIndexBuffer(int Width, int Height);

		GLuint IndexList;
		GLuint VertexList;
		int NumberOfElements;

};


#endif

void CTERRAIN::Init()
{

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glClientActiveTextureARB(0);

	InitVertexBuffer(64, 64);
	InitIndexBuffer(64, 64);

}

void CTERRAIN::Render()
{	
	glBindBuffer(GL_ARRAY_BUFFER_ARB, VertexList);
	glVertexPointer(3, GL_FLOAT, 0, (float *)NULL);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, IndexList);
	glDrawElements(GL_TRIANGLE_STRIP, NumberOfElements, GL_UNSIGNED_INT, 0);
} 

void CTERRAIN::InitVertexBuffer(int Width, int Height)
{

	if (VertexList > 0)
		glDeleteBuffers(1, &VertexList);
	glGenBuffers(1, &VertexList);	

	glBindBuffer(GL_ARRAY_BUFFER_ARB, VertexList);
	glBufferData(GL_ARRAY_BUFFER_ARB, sizeof(GLfloat) * Height * Width * 3, NULL, GL_STATIC_DRAW_ARB);

	int vertOffset = 0;

	GLfloat *VertexBuffer = (GLfloat *)glMapBuffer(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
	int currentIndex = 0;

	for (int z = 0; z < Height; z++)
	{
		for (int x = 0; x < Width; x++)
		{
			// Verticies.
			VertexBuffer[vertOffset]   = (float)x;		
			VertexBuffer[vertOffset+1] = 0;
			VertexBuffer[vertOffset+2] = (float)z;
			vertOffset += 3;

		}
	}
	glUnmapBuffer(GL_ARRAY_BUFFER_ARB);
}

void CTERRAIN::InitIndexBuffer(int Width, int Height)
{

	if (IndexList > 0)
		glDeleteBuffers(1, &IndexList);
	glGenBuffers(1, &IndexList);

	NumberOfElements = ((Height-1) * (Width*2+2))-2;
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, IndexList);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(GLuint) * NumberOfElements, NULL, GL_STATIC_DRAW_ARB);

	GLuint *IndexBuffer = (GLuint *)glMapBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
	int currentIndex = 0;

	for (int z = 0; z < Height-1; z++)
	{
		for (int x = 0; x < Width; x++)
		{
			if (x == 0 && z != 0)
				IndexBuffer[currentIndex++] = x + (z * Width);

			IndexBuffer[currentIndex++] = x + (z * Width);
			IndexBuffer[currentIndex++] = x + ((z+1) * Width);

			if (x == Width-1 && z != Height-2)
				IndexBuffer[currentIndex++] = x + ((z+1) * Width);
		}
	}
	glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB);
}






[Edited by - Dragon_Strike on October 17, 2006 11:09:01 AM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Dragon_Strike
...
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
...
Where are your texture coordinates?

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor
Quote:
Original post by Dragon_Strike
...
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
...
Where are your texture coordinates?


that solved it... thx.. ofr some reoson i was convinced that it shoudlnt matter iv i enable it without defining..

Share this post


Link to post
Share on other sites
Quote:
Original post by Dragon_Strike
that solved it... thx.. ofr some reoson i was convinced that it shoudlnt matter iv i enable it without defining..
NVIDIA drivers tend to ignore frivolously enabled vertex array state while ATI drivers tend to let you know something's wrong (ie: crash).

EDIT: I just tested it on my NVIDIA Quadro card at work and it crashes. Perhaps it is only the drivers for their workstation cards, or maybe all their newer drivers? I'll check on my GeForce at home later. Unfortunately my computer with the Radeon in it is indefinitely out of commission so I won't be able to check that.

EDIT2: Alright, for those of you that care, it crashes on my GeForce 7800 as well with 91.47 drivers. I may be wrong but I'm pretty sure on older NVIDIA drivers it would ignore it. Personally I'm glad they don't anymore.

[Edited by - Kalidor on October 17, 2006 6:46:47 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement