Texture questions - Beginner

Started by
2 comments, last by Talib 19 years, 10 months ago
Hi I set up my directx to 800x600 mode. Then I created a square via a trainglestrip (two triangles) with a white diffuse color. Then I created a 800x600 jpg file, loaded it in with D3DXCreateTextureFromFile() and plopped it on my surface and tadda it works. Added four extra lines of code and now it rotates. (But thats beyond the point) Q1: I did not set up the material for my surface, yet it seems to be displayed correctly. Is this becaue I switched lighting off or does it default to a certain value? Q2: In the book Strategy Game Programming with DX9 they do the same I do, except split the image into smaller 256x256 textures, do some transforming and other stuff (by that sentence you realize I don''t understand what they are doing), and mumble something about cards only being able to handle textures of 2x2, 4x4, ..... ,256x256. Yet my 800x600 texture gets displayed nicely. Any insight? Q3: In my program the camera position gets set every time the scene renders. Can you rather do this a single time and will dx remember it or is camera positioning overwritten evry time you render? (sorry, not a texture question) Q4: How do I get my texture not to be stetched the whole size of the surface? Q4.1: Then place it on different areas of my surface. I think it has something to with transforming. But haven''t grasped that concept yet. Any help would be appreciated Thanks Talib
Try, try and fucking try again.
Advertisement
quote:Original post by Talib
Q1: I did not set up the material for my surface, yet it seems to be displayed correctly. Is this becaue I switched lighting off or does it default to a certain value?


When you have lighting off it uses the vertex color from the vertex if present and ignores materials. If you turn on lighting it uses the material that is set instead of vertex colors together with the lights defined (ambient, directional or spot/point lights).

quote:Q2: In the book Strategy Game Programming with DX9 they do the same I do, except split the image into smaller 256x256 textures, do some transforming and other stuff (by that sentence you realize I don''t understand what they are doing), and mumble something about cards only being able to handle textures of 2x2, 4x4, ..... ,256x256. Yet my 800x600 texture gets displayed nicely. Any insight?


Your texture gets loaded as a 1024x1024 texture, with the upper left part filled in. Then you copy the 800x600 part to the surface. With createtexturefromfileex() you can specify extra options for stretching/filtering etc.
If you purely use the texture to put it on a surface, maybe you can use createsurfacefromfile() ? (I think that one exists)

quote:Q3: In my program the camera position gets set every time the scene renders. Can you rather do this a single time and will dx remember it or is camera positioning overwritten evry time you render? (sorry, not a texture question)


If you do nothing else you can set the camera position (matrix) once and forget about it. Or you can include a boolean and only use set the view/projection matrix when it is set to true and then reset it to false, and set it to true whenever your camera moves. But this is probably irrelevant in 2D.
quote:Original post by Talib
Q1: I did not set up the material for my surface, yet it seems to be displayed correctly. Is this becaue I switched lighting off or does it default to a certain value?

Yes. With lighting off you don''t need materials AFAIK.

quote:Original post by Talib
Q2: In the book Strategy Game Programming with DX9 they do the same I do, except split the image into smaller 256x256 textures, do some transforming and other stuff (by that sentence you realize I don''t understand what they are doing), and mumble something about cards only being able to handle textures of 2x2, 4x4, ..... ,256x256. Yet my 800x600 texture gets displayed nicely. Any insight?

D3DXCreateTextureFromFile can probably fix it up for you (as described in the first response), but more importantly newer cards (most from the DX8 generation or newer) can use non-power-of-2 textures with some restrictions. Look at the DirectX documentation regarding CAPS.

quote:Original post by Talib
Q4: How do I get my texture not to be stetched the whole size of the surface?

Change the texture coordinates on each of the vertices. Note that the texture will be tiled, extended or what not based on your texture stage settings. Generally you just size the quad to how large you want the picture to be before rendering.

quote:Original post by Talib
Q4.1: Then place it on different areas of my surface. I think it has something to with transforming. But haven''t grasped that concept yet.

If by "surface" you mean "screen", then yes: you must transform the quad either by using the world matrix or by simply using a dynamic vertex buffer and feeding the quads manually to the graphics card every frame (pretty common in 2D-in-3D graphics).
quote:
Q2: In the book Strategy Game Programming with DX9 they do the same I do, except split the image into smaller 256x256 textures, do some transforming and other stuff (by that sentence you realize I don''t understand what they are doing), and mumble something about cards only being able to handle textures of 2x2, 4x4, ..... ,256x256. Yet my 800x600 texture gets displayed nicely. Any insight?



The reason they do this is to support more hardware. Some cards have a max texture size of 256x256 (mostly older cards). So, they map the image in chunks of 256x256.

Chris
Chris ByersMicrosoft DirectX MVP - 2005

This topic is closed to new replies.

Advertisement