Sign in to follow this  
Sindharta Tanuwijaya

Getting the value of a texel

Recommended Posts

Hi, I am trying to implement a "reduce" method, a simple GPU method to calculate a single value from all texel values in a texture, for example their maximum value, minimum value, etc. After I do some rendering to smaller texture recursively until the width of the target texture became 1, I am wondering how I can get the value of the only texel in that texture so that I'll be able to use it in my application? Thanks in advance. Sindharta T.

Share this post

Link to post
Share on other sites
Hm, I am quite new to this "rendering to a texture" process, so based on my textbook, I am using ID3DXRenderToSurface to render to a texture.
I checked around, and perhaps just like what you had mind, I found out that it is also possible to render to a texture by using IDirect3DDevice9::SetRenderTarget.
Do you have any opinion which one is more efficient? Or if they are just the same?

In any case, I succeeded in finding the color, but it seems that the code is too long, because I have to create a new texture. It seems that I can't get the DC from the texture directly because it is not D3DUSAGE_DYNAMIC. I also tried to assign D3DUSAGE_DYNAMIC to my target texture directly but it failed.
I included my code below, so please tell me if you have some comments.

Sindharta T.


IDirect3DSurface9* top_surface = 0;

//get the surface format
D3DSURFACE_DESC surface_desc;

//create temporary texture
IDirect3DTexture9* texture;
hr = D3DXCreateTexture(m_pD3DDevice,m_iTextureWidth,m_iTextureHeight,0,D3DUSAGE_DYNAMIC,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&texture);
IDirect3DSurface9* temp_surface = 0;


HDC dc = 0;
hr = temp_surface->GetDC(&dc);

COLORREF col = GetPixel(dc,iX,iY);
BYTE r = GetRValue(col);
BYTE g = GetGValue(col);
BYTE b = GetBValue(col);


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this