Jump to content

  • Log In with Google      Sign In   
  • Create Account

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: 693

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: 13599

Like
0Likes
Like

Posted 19 January 2013 - 06:11 PM

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


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 mhagain   Crossbones+   -  Reputation: 7978

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: 693

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