Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am working at a game that has lots of procedural content. I had built a game engine using OpenGL that handles everything needed for creating a basic 2D game, sprites, primitives, blending, polygons etc. At a particular moment I decided to implement target textures to obtain interesting effects and problems started to arise: Sometimes the engine did not initialize OpenGL and GLEW properly and could not isolate the exception. Finally I abandoned the idea of using OpenGL because of similar issues(SOMETIMES cannot use newer GLEW functions...NOTE:drivers up to date). I decided to use DX11 instead and take benefit from the new technologies of the latest GPUs. So I did. Now I am porting my engine to DX11 and I am quite stuck.

I had procedures to be called in a render() function, like
engine->gfx_render_triangle_list(pointer)
which in principle just called a procedure like

glBegin(GL_TRIANGLES);
...
glVertex2f(.....);
...
glEnd();

Now the problem that arises for me is the new pipeline of DX11.Load up vertices in the VertexBuffer, process them by the VertexShader then fill them with pixels and trasform with the PixelShader. This is great as I have full access to what is being displayed on the screen, but, how do I do it the 'old-fashion' way?

I mean, how do I draw primitives like in OpenGL, each frame sending unique, new triangles to the screen. I didn't find any resources that explain this and I cannot think this through myself, loading some vertices in the vertex buffer is designed for meshes that are human made and static and they are only transformed by the shaders.

Long story short: How do I implement my old gfx_render_triangle_list using DX11? NOTE:My engine will be used as a DLL

share|improve this question
1  
What does "implement target textures" mean? Also, wouldn't it make sense to ask us about those mysterious problems you were having that you couldn't isolate before abandoning your codebase and trying to use a completely different API? –  Nicol Bolas Mar 23 '13 at 4:10
    
By implement, I meant to take use of the Glew procedures to obtain such effect. I found content about my issue on this page, exact problem, had solutions but didn't work for me. Also DX11 has more hardware support, even though they are pretty similar. –  kosmync64 Mar 23 '13 at 4:48
    
By "target textures", do you mean offscreen rendering / render-to-texture? If so, that's something that LOTS of people do in OpenGL all the time, and I'm sure whatever issues you had with it, they can be fixed. OpenGL is a modern API and can access as many hardware features as DX11 can. –  Nathan Reed Mar 23 '13 at 6:12
    
Yes. The problem is that glFramebufferTexture() and all the buffer texture related functions are NULL in some occasions and don't know why and when. –  kosmync64 Mar 23 '13 at 15:01

1 Answer 1

up vote 5 down vote accepted

The glBegin/glEnd API is actually deprecated (i.e. you're not supposed to use it anymore) in OpenGL, and Direct3D has no equivalent functionality. This is as it should be, because making several function calls to specify each vertex is horrifically inefficient if you have any substantial amount of geometry.

The modern way to do this - in either API - is with vertex buffers, which can be static or dynamic. Static vertex buffers are typically used for models that are loaded once from disk and rendered many times without alteration. Dynamic vertex buffers are used for things like particle systems, where the geometry changes every frame. It sounds like for your animating procedural geometry, dynamic vertex buffers are the way to go.

There's a more in-depth tutorial on D3D11 dynamic vertex buffers here - and note that the same thing can be done in OpenGL, with vertex buffer objects - but the basic idea is as follows:

  1. During startup, create a vertex buffer with "dynamic" usage.
  2. Each frame, "map" the buffer with the "discard" flag. This gives you a pointer to the buffer's memory. The "discard" flag means you don't need access to the previous contents of the buffer (since you're going to regenerate it from scratch anyway). This allows the vertices to be double-buffered (or triple-or-more-buffered) under the hood by the graphics driver, which is necessary to keep the CPU and GPU running efficiently.
  3. Using the pointer, fill the buffer with your vertices, generating them however you please.
  4. Unmap the buffer and render it.
share|improve this answer
    
You can also use blogs.msdn.com/b/shawnhar/archive/2012/10/12/… to make the API a bit closer to the OpenGL way of doing things. –  Adam Mar 23 '13 at 12:49
    
Does this primitive batch work with shaders, as they say "it does not provide shaders" then "it can work with any other shader" –  kosmync64 Mar 23 '13 at 15:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.