Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Vertex Buffers in OpenGL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 OzgurEra   Members   -  Reputation: 793

Like
0Likes
Like

Posted 19 January 2013 - 05:26 PM

Actually, It's not an OpenGL question.

This is how I draw things in OpenGL:

glEnableClientState (GL_VERTEX_ARRAY);	
glEnableClientState (GL_NORMAL_ARRAY);	
glEnableClientState (GL_TEXTURE_COORD_ARRAY);		
glVertexPointer(3, GL_FLOAT, sizeof(VertexBuffer), obj->m_vertices[0].vertex);	
glTexCoordPointer(2, GL_FLOAT, sizeof(VertexBuffer), obj->m_vertices[0].texCoord);	
glNormalPointer(GL_FLOAT, sizeof(VertexBuffer), obj->m_vertices[0].normal);			
glDrawElements (GL_TRIANGLES, obj->indicesCount, GL_UNSIGNED_INT, obj->indices);					glDisableClientState (GL_VERTEX_ARRAY);	
glDisableClientState (GL_NORMAL_ARRAY);	
glDisableClientState (GL_TEXTURE_COORD_ARRAY);



As you see here, I don't use any memcpy..

And this is how I have to draw in DirectX: (Pseudo)

D3DVERTEX *ptr = NULL;
app.getDevice()->CreateVertexBuffer(sizeof(quad),                                    
D3DUSAGE_WRITEONLY,                                    
0,                                    
D3DPOOL_MANAGED,                                    
&vertex_buffer,                                    
NULL);
vertex_buffer->Lock(0, 0, (void**)&ptr, 0);
memcpy((void*)ptr, (void*)vetices_of_quad, sizeof(vetices_of_quad));
vertex_buffer->Unlock();




As you see here, I have to use a "memcpy" each frame.. Why each frame, because I can't keep my LPDIRECT3DVERTEXBUFFER9 object..

I just want to hold my vertex data in my own vertex buffer class (VertexBuffer), and be able to use it in both OpenGL and DirectX, without copying the data each frame..

I don't know DirectX much.. I'm a newbie.
Please help sad.png

(BTW, sorry for my bad English)


Edited by FreOzgur, 30 January 2013 - 07:45 AM.


Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 18900

Like
0Likes
Like

Posted 19 January 2013 - 06:11 PM

because I can't keep my LPDIRECT3DVERTEXBUFFER9 object..
And why not?


L. Spiro

#3 mhagain   Crossbones+   -  Reputation: 9463

Like
1Likes
Like

Posted 19 January 2013 - 07:11 PM

Something seriously wrong if that's the way you're drawing in D3D; the equivalent D3D code should look more like this:

device->SetStreamSource (...);
device->SetVertexDeclaration (...);
device->SetIndices (...);
device->DrawIndexedPrimitive (...);

However, from the look of things, you're not even using vertex buffers at all, but system memory pointers instead, so the following may be more appropriate if so:

device->SetVertexDeclaration (...);
device->DrawIndexedPrimitiveUP (...);

What's more, if you're just using the fixed pipeline, you don't even need to bother creating a vertex declaration at all, so it becomes:

device->SetFVF (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1);
device->DrawIndexedPrimitiveUP (...);

As you can see, all of these cases are substantially simpler than the GL code.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 OzgurEra   Members   -  Reputation: 793

Like
0Likes
Like

Posted 19 January 2013 - 08:46 PM

Actually I won't need DirectX codes. I'm just writing a renderer, I will implement it using OpenGL, but I want it to become flexible. So I just want things to be correct, and won't be a problem when I decide to write a DirectX renderer.
 

My VertexBuffer class keeps the system pointers, and it seems that I can use them both in OpenGL and DirectX..

Thank you so much mhagain.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS