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

Procedural Textures.... How?

Started by Xgkkp May 27, 2002 at 4:16 PM 17 replies 450+ views
Original Post
Xgkkp
Xgkkp
I am not talking about any specific algorithms, but more how to generate them onto a surface that you can use as a texture/sky/ whatever. I really wanna start experimenting but I need to see some results to see if it has worked... ---------------------------------------------------------- Note: Don''t kill me for cross posting mod''s! I assume Dx and openGl have diff implementations, so posted in both forums...
Melraidin
Melraidin
The generation algorithm will be the same for both DX and OGL, so feel free to DELETE YOUR CROSS POSTS.
Vaporisator
Vaporisator
But his question is how to USE them not to generate them! And how to use them is definetly different in OpenGL and DirectX (also the mechanism is the same).


Yesterday we still stood at the verge of the abyss,
today we''re a step onward!
Yesterday we still stood at the verge of the abyss,today we're a step onward! Don't klick me!!!
Outworlder
Outworlder
Bah! Unless he has a clone, he will not be able to do both at the same time.
Gaiomard Dragon-===(UDIC)===-
Xgkkp
Xgkkp
ok, I forgot how to delete double posts....


"I am not talking about any specific algorithms"....


and.. I want to get a general idea of the implementation for both, so I can focus on actually doing it, rather than messing around with loads of implementation. I do know a little of dx and opengl, enough to render stuff and texture.
Prosper/LOADED
Prosper/LOADED
NVidia has some stuff about procedural texturing. Check their site.
Shadows
Shadows
If you''re just looking for how to store them to a texture you would just lock the texture surface and plot the pixels on that surface, I can post some code if you''re interested.

Regards Fredrik
Xgkkp
Xgkkp
That would be great, I''ve never been able to get locking working before, and I really mainly want to be able to just run the algorithm.
Xgkkp
Xgkkp
mmm... no code posted.. I had a try on my own, but this code causes an unhandled exception:


D3DLOCKED_RECT *locked = 0;
g_pTexture->LockRect(0, locked, NULL, 0);

DWORD *bits;
bits = (unsigned long *)locked->pBits;

for (int i = 20; i < 300; i++)
bits = 0xFFFF0000;

g_pTexture->UnlockRect(0);

bits = NULL;


Shadows, a code posting would be greatly appreciated :-)

[edited by - Xgkkp on May 29, 2002 5:45:21 PM]
LordShade
LordShade
You forgot about the pitch. Even though you may have asked for a bmp that is 128x128, DirectX may allocate a larger rect due to hardware support issues. Pitch is the actual number of pixels in a horizontal line.

This function looks for a particular color and makes it transparent.

Note: this is a 32 bpp bitmap, RGBA.


          
HRESULT hRet;
DWORD* pdwPixel;
D3DLOCKED_RECT lockRect;

// let's look at the description

D3DSURFACE_DESC surfDesc;
::memset(&surfDesc, 0, sizeof(D3DSURFACE_DESC));

hRet = pITexture->GetLevelDesc(0, &surfDesc);

// does it support an alpha channel? We know it does cause we allocated it



hRet = pITexture->LockRect(0,
&lockRect,
NULL,
0);

// check the pitch

// we can just copy it

BYTE* pbtBits = reinterpret_cast<BYTE*>(lockRect.pBits);

for(DWORD dwHOffset = 0; dwHOffset < surfDesc.Height; dwHOffset++)
{
for(DWORD dwWOffset = 0; dwWOffset < surfDesc.Width; dwWOffset++)
{
char* pcPixel;

pdwPixel = reinterpret_cast<DWORD*>(&pbtBits[(dwHOffset * lockRect.Pitch) + (dwWOffset * 4)]);
pcPixel = reinterpret_cast<char*>(pdwPixel);
if(dwTransparentColor == *pdwPixel)
{
pcPixel[3] = 0;
} else {
pcPixel[3] = 255;
}
}
}

pITexture->UnlockRect(0);


[edited by - LordShade on May 30, 2002 3:09:02 AM]

[edited by - LordShade on June 2, 2002 3:19:33 PM]
Xgkkp
Xgkkp
Okay, update. I still can't get it working. I tried


  	// Mess up the Texture

D3DLOCKED_RECT *recto = NULL;
g_pTexture->LockRect(0, recto, NULL, 0);

DWORD *pixels = (DWORD*)recto->pBits;

for (int j = 0; i< 300; i++)
pixels[i] = 0x7FFF0000;

g_pTexture->UnlockRect(0);
recto = NULL;

But it has an Unhandled Exception - On the call to LockRect.

I would install the Debug runtime but my SDK is 8.0 or something, whereas Xp's version seems later, so it won't install any runtime.

[edited by - Xgkkp on June 10, 2002 12:44:59 PM]
Xgkkp
Xgkkp
Null pointer so that it initialises it to something, otherwise the compiler complains. I am passing it a pointer to fill for me, so a Null pointer shouldn't affect it.


D3DLOCKED_RECT recto;
g_pTexture->LockRect(0, &recto, NULL, 0);

is, to my knowledge Exactly the same as saying
D3DLOCKED_RECT	*recto = NULL;
g_pTexture->LockRect(0, recto, NULL, 0);

just with the pointers the other way around.

[edited by - Xgkkp on June 10, 2002 12:58:35 PM]
megajocke
megajocke
No it''s definately not the same thing. If you do it like you did
first you wont have any memory allocated for it. If you need to zero
out the struct you have to use ZeroMemory...
Xgkkp
Xgkkp
Thanks a lot!!! It works now.

I forgot I had to allocate Memory.

You can tell you''re getting better at programming when You stop forgetting ;''s and start doing Memory things wrong.
megajocke
megajocke
quote:
Original post by Xgkkp
You can tell you''re getting better at programming when You stop forgetting ;''s and start doing Memory things wrong.


=)
LordShade
LordShade
Usually if you''re gonna return something that will be allocated in a function you should take a pointer to a pointer as a parameter.

That''s how I do it anyway. DirectX seems to like that methodology too.
erejam
erejam
I think LockRect doesn''t allocate memory.

D3DLOCKED_RECT *recto = NULL;
res = g_pTexture->LockRect(0, recto, NULL, 0);

this always results in "res != D3D_OK" ....

Topic Locked

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

Sign in to reply to this topic.