LoadImage question

Started by
5 comments, last by Leprosy 23 years, 8 months ago
Is there any difference in the way DX stores a 3d suface for texture redering and a 2d image? im trying to get Brakets code to load a specific region from a bitmap image into the texture. This of course would be easy if LoadImage function took an x and y offset, but the books I have seem to suggest that it doesnt. Should I take this to the general D3D help lobby ?
Advertisement
other than the caps for the surface, (DDSCAPS_TEXTURE instead of DDSCAPS_OFFSCREENPLAIN), and certain size restrictions (textures have to have a width and height that is a power of two), there is really no difference between a normal offscreen surface and a texture surface, as far as you the programmer are concerned.

Get off my lawn!

Change the offsets in the vertex stucture:

Vertex[0].tu = xStart;
Vertex[0].tv = yStart;
Vertex[1].tu = xEnd;
Vertex[1].tv = yStart;
Vertex[2].tu = xStart;
Vertex[2].tv = yEnd;
Vertex[3].tu = xEnd;
Vertex[3].tv = yEnd;

Say you had a texture that is 256x256 and in this texture there were 16 64x64 textures then to select the third texture set the variables to:

xStart = 0.75f;
yStart = 0.0f;
xEnd = 1.0f;
yEnd = 0.25f;

et-vola your texture that is in the third position (assuming you are going left to right, top to bottom).

I''m doing this in my ISO prog at the moment, it works great, and helps in reducing the number of calls to SetTexture() if you manage the texures right.
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
quote:Original post by Steven

Change the offsets in the vertex stucture:

Vertex[0].tu = xStart;
Vertex[0].tv = yStart;
Vertex[1].tu = xEnd;
Vertex[1].tv = yStart;
Vertex[2].tu = xStart;
Vertex[2].tv = yEnd;
Vertex[3].tu = xEnd;
Vertex[3].tv = yEnd;

Say you had a texture that is 256x256 and in this texture there were 16 64x64 textures then to select the third texture set the variables to:

xStart = 0.75f;
yStart = 0.0f;
xEnd = 1.0f;
yEnd = 0.25f;

et-vola your texture that is in the third position (assuming you are going left to right, top to bottom).

I''m doing this in my ISO prog at the moment, it works great, and helps in reducing the number of calls to SetTexture() if you manage the texures right.



I think this is what I would like to do - thanks to both of you the info is much appreciated.

One last D3D question what does the .75f and 1.0f stand for? is it a percentage of the entire image? if so, should i be .5f and .75f for the 3rd tile and .75 and 1.0 for the fourth? thank

Lep
I was actually counting from 0

I''ve uploaded my current engine test, and the source code to my website:

www.stevesprogpage.f2s.com

I''m still looking into new ways to implement the images, like using a larger image size (256x256 is the max for most cards I think)
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
Alright I think I understand how some off this works but im still confused as to how you are filling Texture up with information. What exactly does the query interface
Surface->QueryInterface( IID_IDirect3DTexture2, ( void **)&Texture );
function do?
more importantly how does the following section of code fill Texture up with information?

HBITMAP hBM;
BITMAP BM;
HDC hDCImage, hDC;

hBM = ( HBITMAP ) LoadImage( NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION );
if (hBM == NULL) {
exit(10);
};

GetObject( hBM, sizeof( BM ), &BM );

hDCImage = CreateCompatibleDC( NULL );
SelectObject( hDCImage, hBM );

if( SUCCEEDED( Surface->GetDC( &hDC )))
{
BitBlt( hDC, 0, 0, Width, Height, hDCImage, 0, 0, SRCCOPY );
Surface->ReleaseDC( hDC );
} else {
exit(10);
};

DeleteDC( hDCImage );
DeleteObject( hBM );

How does this fill texture up with information and not Surface?
Why is there a Surface and not just a texture LPDIRECT3DTEXTURE2? ***Ive tried to do blits to Surface and it doesnt change what the texture looks like.-***** So is texture a seperate surface from surface? or is texture pointing to the same location in memory that surface is? what the hell is going on??????

Lep - *confused*


Edited by - Leprosy on July 24, 2000 11:33:36 PM
If that is my code (and it looks familure) then:

I''m loading the bitmap directly onto a surface as I normally do.

The line:
Surface->QueryInterface( IID_IDirect3DTexture2, ( void **)&Texture );
was used for DirectX 6, but I could not find the relevant code in DirectX 7, so a quick read of the SDK resulted in me dropping that code (I just commented it out) and it still works. As for what it does, you will have to look at the SDK for DirectX 6.

Also I do not use texture pointer anymore, I use the surface directly.

The code you printed up there was the standard and quick way to load in a bitmap from a disk, using the API function LoadImage();

As for your last question (whichh I did not answer correctly) the texture co-ords go from 0 to 1 in both direction (U and V), so if the offset to a texture is 75% accross and 25% down then the U,V co-ord would be 0.75,0.25. If you know the pixel offset and needed the UV offset then divide the pixel offset by the size of the image i.e:

U = PixelXOffset / BitMapWidth
V = PixelYOffset / BitMapHeight

I may have the U and V the wrong way around, but the algorithm is the same.

I''m not an expert at 3D texture rendering, most of this is from a book I have on how to write your own Raytracer in Amiga BASIC(the book is aimed at the Amiga but it is full of 3D information).

If you want any more help with code you can e-mail me on steven.harrison@libertysurf.co.uk or steven.harrison@tesco.net

If you want to use my DX7 conversion of Brackets code you can, as you can see it''s only on one level and I added the ability to display a left and right wall to the map.

I''f I have not made myself clear on anything I''ll try and explain it better
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site

This topic is closed to new replies.

Advertisement