Jump to content
  • Advertisement
Sign in to follow this  
RaptorZero

glDrawArrays not working for me

This topic is 4819 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

OK, this started with me trying to make VBOs work for drawing the terrain in my project. Well, it didn't work (if it did you wouldn't be reading this). To check whether all my vertex data was being generated correctly, I made it draw through a nasty pile of glVertex3f and it worked OK. So I put this data in a simple glDrawArray and it didn't work either. So I tried to simplify everything as much as possible and I ended up with this code in the drawing loop:
	float Triangle[] =
	{
		-1.0, -2.0, 0.0,
		3.0, 0.0, 0.0,
		0.0, 1.5, 0.0
	};

#ifdef USE_ARRAY
	glVertexPointer(3, GL_FLOAT, 0, Triangle);
	glDrawArrays(GL_TRIANGLES, 0, 3);
	glDisableClientState(GL_VERTEX_ARRAY);

	return;

#else

	glBegin(GL_TRIANGLES);
	glVertex3fv(&Triangle[0]);
	glVertex3fv(&Triangle[3]);
	glVertex3fv(&Triangle[6]);
	glEnd();

	return;
#endif //USE_ARRAY

This is the simplest it can get and it still shows the same symptoms as before: if I '#define USE_ARRAY' then it won't work, but if I don't do it.. it works. I hate posting this kind of problem because it's either a very stupid mistake or a minimum detail hidden somewhere among thousands of lines of code, but any help is would be great! What could be going wrong or what did I miss? I'm using C++ (you may have noticed), my video card is a GeForce 4 mx 440 (it's not that crappy, is it?) and I've cursed my computer 20 times till now. Any other information just ask. (5 minutes break before my brain burns out)

Share this post


Link to post
Share on other sites
Advertisement
Since you have a glDisableClientState there, but no glEnableClientState, the obvious question would be: do you enable the vertex array at all?

Share this post


Link to post
Share on other sites
I knew it was somethig that stupid, the strange thing is that glEnableClientState doesn't show up in NeHe Lesson 45 (just in the downloaded source code) but glDisableClientState does. Anyone knows why?

Thanks a lot Brother Bob, you saved me.

Share this post


Link to post
Share on other sites
Quote:
Original post by RaptorZero
Anyone knows why?


Line 228 and 229 of Lesson45.cpp

// Enable Pointers
glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays


As for why it's not on the lesson itself, not all code is put into the tutorials, but it does say that you must change the state.

Quote:
To use Vertex Arrays (and VBOs), you need to tell OpenGL what data you are going to be specifying with your memory. So the first step is to enable the client states GL_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY. Then we are going to want to set our pointers. I doubt you have to do this every frame unless you have multiple meshes, but it doesn't hurt us cycle-wise, so I don't see a problem.


[smile]

Share this post


Link to post
Share on other sites
No problem, no need to be sorry. Only reason I looked into it was finding mistakes such as those are really rare in large tutorials (just because so much text, finding errors is 'challenging'), and if this was one, then an email to NeHe would be benefitial for anyone else using that tutorial because they'd probabally have the same problem [wink].

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!