Skip to main content
GameDev.net gamedev.net
🔒 Locked

Render the screen using a specified frame buffer

Started by Quaid Tseng Aug 23, 2006 at 8:30 AM 2 replies 950+ views
Original Post
Quaid Tseng
Quaid Tseng
Can anyone give some tips in directx that how can I render the screen like.. int* buffer = new int [640*480*3]; // 3 for RGB function_render_screen(buffer); Thank for your reply.
Illco
Illco
The first thing is to ask why you would want that -- with the layout of current hardware it will be horribly slow. In short, there is probably a quicker way of achieving what you want.

Now if you still want it, you can try the following approach. You can lock a render target and write directly into it kind of like the way you showed in the example. The point is, you need to know the format of the render target in order to be able to compute the location of a pixel.

For short, let's assume a 4-byte RGBA format. You can lock the texture by calling LockRect(). This will give you a structure specifying the pitch of the texture (see the SDK documentation) and a pointer to the bits of the texture. With the format in hand you can now touch the iternals.

Don't forget to unlock the texture afterwards. Furthermore you need to render it to the backbuffer using a quad.

(or maybe you could lock the backbuffer directly and write into it)

Greetz,

Illco
Quaid Tseng
Quaid Tseng
Hey Illco, thank for your help.

Actually I want to develop a "RayTracing" engine

And in raytracing, we need to shoot rays for each pixel
into the scene to sample the objects' surface texture.

After all the rays returned with the samples,
thus I got the "sample values"(RGBA) for all screen pixels,
and directly render the screen using these values.

Something I don't understand, that you say "render it to the backbuffer using a quad."
What "quad" stands for? please:)

And do you know some functions that I can write the arrays into
the backbuffer?

Perhaps there's better ways to implement raytracing environment
without directly writing backbuffers.

Thanks in advance:)
jollyjeffers
jollyjeffers
A "quad" is just a pair of triangles arranged as a square/rectangle; in this instance one that matches up with the rectangular shape of the screen.


If you're doing a ray-tracer then chances are it doesn't make much difference what route you get it to the screen using D3D - the performance of the memory copy isn't likely to be your main problem [wink]

Illco's method is probably the best though. If you can pick a texture format that matches your system-memory array then you can probably just use a memcpy_s() call to copy it straight across (provided you check the pitch is okay). Rendering it via a textured quad also opens up the possibility of using a post-processing pixel shader. This may well prove to be useful if you want to do some advanced effects...


hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.