Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

EXT CSQC COPYTOTEXTURE

From Quake Wiki

Revision as of 11:28, 27 July 2008 by KrimZon (talk | contribs) (New page: ===Extension Proposal=== Suggested extension for copying a portion of the screen to a texture in client side QuakeC. This will essentially be a wrapper for the OpenGL function ''glCopyTexI...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Extension Proposal

Suggested extension for copying a portion of the screen to a texture in client side QuakeC. This will essentially be a wrapper for the OpenGL function glCopyTexImage2D (http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/copyteximage2d.html).

Builtin function:

vector csqc_copytotexture(float x, float y, float w, float h, string texture);

x, y, w, and h specify the portion of the screen from which to copy pixels. They use the exact same coordinate space as R_SetView does for the view portal, were the top left of the screen is 0, 0, and the width and height are vid_conwidth and vid_conheight respectively.

texture specifies the name of the destination texture which will receive the new data. It is a string path and filename which would have been previously passed to precache_pic. The currently loaded texture will be overwritten with new pixels, though it may not necessarily persist beyond a video subsystem restart.

If the engine supports automatically precaching textures as soon as they are used, then the same should be implemented for this extension - the texture name will no longer need to have been precached with a dummy texture.

glCopyTexImage2D requires that the destination texture have width and height be a power of two, though they don't have to be the same length. csqc_copytotexture should accept any width and height, and automatically use a larger texture. The vector returned is the s and t texture coordinates of the corner of the desired texture within the larger power-of-2 sided texture.

Possible Issues

glCopyTexImage2D copies pixels upside-down compared to quake's 2D coordinate system: Pixel ordering is such that lower x and y screen coordinates correspond to lower s and t texture coordinates.

This means that the texture coordinates will be upside down in QuakeC.

I think the desired image will be aligned to the top left of the texture, but upside down. (It might be aligned to the bottom, have to check).