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:
which in principle just called a procedure like


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 transform 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.

  • 1
    \$\begingroup\$ 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? \$\endgroup\$ Mar 23, 2013 at 4:10
  • \$\begingroup\$ 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. \$\endgroup\$
    – kosmync64
    Mar 23, 2013 at 4:48
  • \$\begingroup\$ 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. \$\endgroup\$ Mar 23, 2013 at 6:12
  • \$\begingroup\$ 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. \$\endgroup\$
    – kosmync64
    Mar 23, 2013 at 15:01

1 Answer 1


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.
  • \$\begingroup\$ 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. \$\endgroup\$
    – Adam
    Mar 23, 2013 at 12:49
  • \$\begingroup\$ Does this primitive batch work with shaders, as they say "it does not provide shaders" then "it can work with any other shader" \$\endgroup\$
    – kosmync64
    Mar 23, 2013 at 15:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .