doing a 'pixel test'

Started by
8 comments, last by billybob 21 years, 9 months ago
i need to look up the color of a pixel on a texture. in qbasic, this was super easy, there has to be a way to look up the color of a pixel at (x, y) of a IDirect3DTexture8 right? i need this because i''m making heightmapped terrain, and i am having severe trouble loading anything other than textures, like meshes and such. is there a way to do a pixel test?
Advertisement
LockRect should work. be careful with reading stuff from video memory, though.

---
Come to #directxdev IRC channel on AfterNET
quote:Original post by niyaw
LockRect should work. be careful with reading stuff from video memory, though.

i have never used directx before, what is a lockRect? and i should be ok reading from video memory if i lock it right? on that subject, since the heightmap is never used once a vertex buffer is created after reading it, should i just release it or create in RAM from the start?

DONT read from vram as its slow. (frames per second becomes seconds per frame very quickly when you read from vram).

for loading meshes you dont need to deal with reading from a texture. just load the file into memory (ie like any other file) then create a vertexbuffer and fill it with the vertices. i suggest reviewing some of the simpler things first since it seems you jumped from qbasic to doing d3d apps rather quickly. its very easy to read from allocated memory (just buff[x+y*buffWidth]

how far along are you with c++? why are you using a texture to load the images? why not just load them yourself instead? you can get image libraries on the net to help ease loading images. i think you should look at some more c++ code and learn about memory allocation and how to deal with files. it will help you in the long run.
quote:Original post by billybob
i have never used directx before, what is a lockRect?

it's a member function of IDirect3DTexture8, see the docs on what it does. see the samples on how to use it (d3dfont.cpp has some writing code).
quote:
and i should be ok reading from video memory if i lock it right?

yes; i meant that reading from video memory is slow.
quote:
on that subject, since the heightmap is never used once a vertex buffer is created after reading it, should i just release it or create in RAM from the start?

loading it to D3DPOOL_SYSTEMMEM will probably be a good idea.

edit: still can't get the quotes right.

---
Come to #directxdev IRC channel on AfterNET

[edited by - niyaw on July 24, 2002 2:38:41 AM]
quote:
yes; i meant that reading from video memory is slow.

that doesnt matter, once its loaded the heightmap its now in an array, which i then have to figure out how to put into a vertex buffer. so once its done reading the heightmap, it doesn''t matter how slow it is.
alright, i''m trying to write a getpixel routine, what i''m doing is locking a 1x1 rectangle of where i''m trying to read. in this case, the pitch would be 1 right? so i could just read the first 32 bits of my locked rectangle? and then do the bitmask stuff to get the rgb out of it right?
quote:Original post by a person
DONT read from vram as its slow. (frames per second becomes seconds per frame very quickly when you read from vram).

i don''t need it to be fast, its only doing the getpixel during loading. once it reads it, the heightmaps are now in an array. heightmap[x][y] = whatever was read from the hieghtmap.
quote:
for loading meshes you dont need to deal with reading from a texture. just load the file into memory (ie like any other file) then create a vertexbuffer and fill it with the vertices. i suggest reviewing some of the simpler things first since it seems you jumped from qbasic to doing d3d apps rather quickly. its very easy to read from allocated memory (just buff[x+y*buffWidth]

i haven''t jumped strait from qb to C++ d3d apps, i did C for a long time with loads of crappy third party libraries.
quote:
how far along are you with c++? why are you using a texture to load the images? why not just load them yourself instead? you can get image libraries on the net to help ease loading images. i think you should look at some more c++ code and learn about memory allocation and how to deal with files. it will help you in the long run.

i''m doing D3DXCreateTextureFromFile(blah blah), and i was thinking about that, getting a bmp loader and putting the pixel values into the array before drawing it.

the way i learned all the languages is reading other peoples code. so i have trouble when it comes to doing things that i''ve never seen the command used before. the samples use a (over)complicated way of loading meshes, thats why i''m having trouble. they deal with all this material and animation stuff, while all i need is the vertexes, texture coords and normals. then i could just use the skin that my friend made for the things. as for the framework of the heightmaps, its already done. all i need is a way to get the heights into it, for now it already makes triangles with texture coordinates, you can set how many blocks a texture goes before it tiles again, all that kind of stuff. the only part i''m having trouble with is getting external file information into the vertex buffers.
quote:Original post by billybob
alright, i'm trying to write a getpixel routine, what i'm doing is locking a 1x1 rectangle of where i'm trying to read. in this case, the pitch would be 1 right? so i could just read the first 32 bits of my locked rectangle? and then do the bitmask stuff to get the rgb out of it right?

you have to be crazy to lock 1x1 rects. lock the entire texture once, do whatever you want with it, then unlock.
quote:
i don't need it to be fast, its only doing the getpixel during loading.

with this code, your loading times will be measured in minutes. just because you are doing loading once doesn't mean you can use the most ridiculously slow way to do it. think for some time.
quote:
i'm doing D3DXCreateTextureFromFile(blah blah), and i was thinking about that, getting a bmp loader and putting the pixel values into the array before drawing it.

instead of d3dx, use good old LoadImage. use GetObject to get a BITMAP out of HBITMAP, and use the bits of the loaded bitmap as your data source. this will be several orders of magnitude faster than locking 1x1 rects in vram.
quote:
the way i learned all the languages is reading other peoples code.

keep in mind that people aren't perfect, and therefore you should never cut and paste. ideally, use the people's ideas to come up with your own implementation, even if it turns out the same as that person's one. copying code prevents you from finding alternative solutions, thus from looking deeply into the problems at hand.

edit: still can't get the quotes right the first time. this is becoming annoying.

edit2: i should make it more obvious: don't write a getpixel routine. forget you know it even exists. you should write a routine to create a mesh out of your image data, and that routine will directly access the image data without any intermediate routines. only this approach will give you acceptable performance.

---
Come to #directxdev IRC channel on AfterNET


[edited by - niyaw on July 24, 2002 4:55:51 AM]
i don''t cut and paste code, what i do is a read their code to see how a routine is used. then i figure out how to use the routine in my code. as for the getpixel routine, i didn''t realize it was THAT slow. loading a bitmap into an array sounds like a better plan, i''ll just do that instead. another idea is to make a small program to load the heightmap my way, and save the resulting mesh as a .x file. then load it when the game loads, instead of a heightmap, so there are no intermedite routines, period.

This topic is closed to new replies.

Advertisement