Hi
I am trying to getting started rendering textures in d3d9, but it only shows a white quad
is it wrong textureflags?somethings missing for making textures enabled?
I am looking at scrontys testing.asm for howto
does it maybe take different flags for taking a .dds which includes 11 levels of mip/mapping?
first I want to get this right
after that I want to change it to work with createtexturefrommemory
Magnus
I am trying to getting started rendering textures in d3d9, but it only shows a white quad
is it wrong textureflags?somethings missing for making textures enabled?
I am looking at scrontys testing.asm for howto
does it maybe take different flags for taking a .dds which includes 11 levels of mip/mapping?
first I want to get this right
after that I want to change it to work with createtexturefrommemory
Magnus
Show your code segment, particularly your initialisation and your rendercode.
Afternoon, daydreamer.
What do you have as data for the vertex buffer?
Remember: It will nolonger have colour values, and will now have texture tu/tv values.
When rendering, do you SetTexture?
Are you loading the texture? Is the Load call failing?
Cheers,
Scronty
What do you have as data for the vertex buffer?
Remember: It will nolonger have colour values, and will now have texture tu/tv values.
When rendering, do you SetTexture?
Are you loading the texture? Is the Load call failing?
Cheers,
Scronty
Afternoon, daydreamer.
What do you have as data for the vertex buffer?
Remember: It will nolonger have colour values, and will now have texture tu/tv values.
When rendering, do you SetTexture?
Are you loading the texture? Is the Load call failing?
Cheers,
Scronty
it was hard to find a small missing Settexture
do I myself have to divide x and y with z, because changing z's doesnt affect anything?
or I have to Zenable it and setup a zbuffer first?
what apis do I need to call first to get:max vram usable for textures
and max x/y size hardware support?
You need to set a View in 3D.
Take a look at the api functions D3DXMatrixLookAtLH and D3DXMatrixPerspectiveFovLH, or just dig around for a procedure called "SetupMatrices", which sets up a fixed 3D camera view using those functions.
You only need to setup the Perspective once.
To implement the simplest kind of realtime camera, you need to call the LookAt function once for every time you "camera" moves or rotates (ie whenever the "camera view" has changed.
Your camera is by default (no Lookat call) located at 0,0,0 and looking into Z.
Just setting up the Perspective should be enough to make the texture scale with Z values.
I just thought I'd waffle a bit to give you some stuff to play with..
Take a look at the api functions D3DXMatrixLookAtLH and D3DXMatrixPerspectiveFovLH, or just dig around for a procedure called "SetupMatrices", which sets up a fixed 3D camera view using those functions.
You only need to setup the Perspective once.
To implement the simplest kind of realtime camera, you need to call the LookAt function once for every time you "camera" moves or rotates (ie whenever the "camera view" has changed.
Your camera is by default (no Lookat call) located at 0,0,0 and looking into Z.
Just setting up the Perspective should be enough to make the texture scale with Z values.
I just thought I'd waffle a bit to give you some stuff to play with..
You need to set a View in 3D.
Take a look at the api functions D3DXMatrixLookAtLH and D3DXMatrixPerspectiveFovLH, or just dig around for a procedure called "SetupMatrices", which sets up a fixed 3D camera view using those functions.
You only need to setup the Perspective once.
To implement the simplest kind of realtime camera, you need to call the LookAt function once for every time you "camera" moves or rotates (ie whenever the "camera view" has changed.
Your camera is by default (no Lookat call) located at 0,0,0 and looking into Z.
Just setting up the Perspective should be enough to make the texture scale with Z values.
I just thought I'd waffle a bit to give you some stuff to play with..
ok so I have to setup 3 matrices?, a camera matrice, a world matrice,a transform matrice with direction 1.0 in lookup and rest zeros and call D3DXMatrixPerspectiveFovLH in renderproc?
I have no intention in making a deep dive in d3d9, just get started with getting hardware accelerated
generate my textures and my meshes and let my hardware do the rendering
I appreciate an example
Here's a procedure originally by Scronty.
Bear in mind everything I said in my last post, as this example is designed to be called EVERY FRAME, ie from the Render code. You could do better with the information in my last post.
However, it does show clearly how to setup all those nasty matrices.
Don't be afraid of matrices, we don't need to mess with them often, when we do we usually use some kind of procedure to do it, so just think of them as big structs, with either 4x4 or 3x3 FLOATs in them.
I hope that stuff helps you, and that you push ahead and get past this hurdle, as it's only a psychological barrier, since you're not used to dealing with matrices, they are new, so they are scary. They don't have to be.
Bear in mind everything I said in my last post, as this example is designed to be called EVERY FRAME, ie from the Render code. You could do better with the information in my last post.
However, it does show clearly how to setup all those nasty matrices.
Don't be afraid of matrices, we don't need to mess with them often, when we do we usually use some kind of procedure to do it, so just think of them as big structs, with either 4x4 or 3x3 FLOATs in them.
;---------------------------------------------------------------------------------------------------------------------
; Name: SetupMatrices
; Desc: Sets up the world, view, and projection transformation matrices.
;-----------------------------------------------------------------------------------------------------------------------
SetupMatrices PROC
LOCAL tmpmatrix:D3DMATRIX
LOCAL tmpmatrix2:D3DMATRIX
LOCAL matWorld:D3DMATRIX
LOCAL matView:D3DMATRIX
LOCAL matProj:D3DMATRIX
.DATA
fpField_of_View FLOAT 0.7853981635f ;( roughly PI / 4 = roughly 90 degree fov )
fpAspect_Ratio FLOAT 1.0f ;Like art apps, 1:1 aspect ratio = noresize
fpNear_Clipping_Plane FLOAT 1.0f ;Anything closer to the cam than this is clipped
fpFar_Clipping_Plane FLOAT 100.0f ;Anything further away than this is clipped
cam_vector D3DXVECTOR3 <0.0f, 3.0f,-15.0f> ;Cam is currently located HERE in 3D space
lookat_vector D3DXVECTOR3 <0.0f, 0.0f, 0.0f> ;Cam is looking @ this point in 3D space
world_UP_vector D3DXVECTOR3 <0.0f, 1.0f, 0.0f> ;UP vector is (0,0,0) --> (0,1,0) = +Y
fptGTms FLOAT 0.0f ;"The Time"
fptGTms2 FLOAT 0.0f ;"The Time / 3"
fptGTmsDivBy FLOAT 1000.0f
fptGTmsDivBy2 FLOAT 3.0f
fptGTmsDivBy3 FLOAT 6.0f
fpmine FLOAT 15.0f
fp2pt0 FLOAT 2.0f
rlNeg2pt0 REAL4 -2.0f
rl0pt2 REAL4 0.2f ; This is half of the mesh-fonts' Extrusion
fptemp FLOAT 0.0f
temp DWORD 0
.CODE
invoke DXUtil_Timer, TIMER_GETAPPTIME
fst fTime
fst fptGTms
fdiv fptGTmsDivBy2
fstp fptGTms2
;========================================================================================
; Perform the World Transformation (translate, rotate, and / or scale the entire universe
; Rotate the text in the middle - uses negated result of Bounding Sphere to center text.
;========================================================================================
invoke D3DXMatrixIdentity,addr matWorld
invoke D3DXMatrixTranslation, addr matWorld, vCenter.x, fp0, rl0pt2
invoke D3DXMatrixRotationX, addr tmpmatrix, fptGTms
invoke D3DXMatrixRotationY, addr tmpmatrix2, fptGTms2
invoke D3DXMatrixMultiply, addr matWorld, addr matWorld, addr tmpmatrix
invoke D3DXMatrixMultiply, addr matWorld, addr matWorld, addr tmpmatrix2
mcall ,IDirect3DDevice8_SetTransform, 256, addr matWorld
;========================================================================================
fld fptGTms ;Make the cam move up and down a lil with Time
fdiv fRadius
mov temp,5
fimul temp
fsincos ;sinf(timeGetTime()/350.0f))
fstp fptemp
fstp cam_vector.y
invoke D3DXVec3Normalize, addr cam_vector, addr cam_vector
fld fp0 ;Move the cam back in Z so we can see better
fsub fptGTmsDivBy3
fsub fRadius
fstp cam_vector.z
;========================================================================================
;Perform the View Transformation (rotate everything to suit the cam orientation)
;========================================================================================
invoke D3DXMatrixLookAtLH, addr matView, addr cam_vector, addr lookat_vector, addr world_UP_vector
mcall ,IDirect3DDevice8_SetTransform, D3DTS_VIEW, addr matView
;========================================================================================
;Perform the Projection Transformation (scale things in x and y based on z , = perspective)
;========================================================================================
invoke D3DXMatrixPerspectiveFovLH, addr matProj, fpField_of_View, fpAspect_Ratio, \
fpNear_Clipping_Plane, fpFar_Clipping_Plane
mcall ,IDirect3DDevice8_SetTransform, D3DTS_PROJECTION, addr matProj
;========================================================================================
ret
SetupMatrices ENDP
I hope that stuff helps you, and that you push ahead and get past this hurdle, as it's only a psychological barrier, since you're not used to dealing with matrices, they are new, so they are scary. They don't have to be.
I hope that stuff helps you, and that you push ahead and get past this hurdle, as it's only a psychological barrier, since you're not used to dealing with matrices, they are new, so they are scary. They don't have to be.
thanks, wrote a dx9 setupmatrices, using pcall instead of mcall, but still no clue
probably something obvious that I miss, could you look at my main code?
;********************************************************************
;**************** SetupMatrices
;********************************************************************
SetupMatrices PROC
LOCAL tmpmatrix:D3DMATRIX
LOCAL tmpmatrix2:D3DMATRIX
LOCAL matWorld:D3DMATRIX
LOCAL matView:D3DMATRIX
.DATA
? ? fpField_of_View? ? ?FLOAT 0.7853981635f
? ? fpAspect_Ratio? ? ? FLOAT 1.0f
? ? fpNear_Clipping_Plane? ?FLOAT 1.0f
? ? fpFar_Clipping_Plane? ? FLOAT 100.0f
? ? cam_vector? ? ? D3DXVECTOR3? <0.0f,3.0f,-150.f>
? ? lookat_vector? ?D3DXVECTOR3? <0.l0f,0.0f,0.0f>
? ? world_UP_vector D3DXVECTOR3? <0.0f,1.0f,0.0f>
.CODE
? ? invoke D3DXMatrixLookAtLH,addr matView,addr cam_vector,addr lookat_vector,addr world_UP_vector
? ? pcall lpd3dDevice.SetTransform,D3DTS_VIEW,addr matView
invoke D3DXMatrixPerspectiveFovLH, addr matView,fpField_of_View,fpAspect_Ratio,\
? ? ? ? ? ? ? ? ? ? fpNear_Clipping_Plane,fpFar_Clipping_Plane
? ? ? ? ? ? ? ? ? ? pcall lpd3dDevice.SetTransform,D3DTS_PROJECTION,addr matView
? ? ? ? ? ? ? ? ? ?
ret
SetupMatrices ENDP
;********************************************************************
;**************** /SetupMatrices
;********************************************************************? ? ? ? ? ? ? ? ? ? ? ? ?
and render
;********************************************************************
;**************** Render
;********************************************************************
Render proc
? ? ;call InitGeometry
? ? ;================================================================
? ? ;============ Clear the backbuffer to a green colour
? ? ;================================================================
? ? pcall lpd3dDevice.Clear, 0, 0, (D3DCLEAR_TARGET), 00h, fp1pt0, 0
? ? ;================================================================
? ? ;============ /Clear the backbuffer to a green colour ;8EC2ADh
? ? ;================================================================
? ? ;================================================================
? ? ;============ Begin the scene
? ? ;================================================================
? ? pcall lpd3dDevice.BeginScene
? ? .if eax == D3D_OK
;-------------------
? ? ? ? call SetupMatrices
? ? ? ? pcall lpd3dDevice.SetTexture, 0, lpTexture
? ? ? ? pcall lpd3dDevice.SetTextureStageState, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1
? ? ? ? pcall lpd3dDevice.SetTextureStageState, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE
? ? ? ? pcall lpd3dDevice.SetTextureStageState, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE
? ? ? ?
? ? ? ? pcall lpd3dDevice.SetStreamSource, 0, lpVB, 0, sizeof(CUSTOMVERTEX)
? ? ? ? pcall lpd3dDevice.SetFVF, D3DFVF_CUSTOMVERTEX
? ? ? ? pcall lpd3dDevice.DrawPrimitive, D3DPT_TRIANGLESTRIP, 0,2 ;D3DPT_TRIANGLELIST
;-------------------
? ? ? ? ;============================================================
? ? ? ? ;============ End the scene
? ? ? ? ;============================================================
? ? ? ? ; End the scene
? ? ? ? pcall lpd3dDevice.EndScene
? ? ? ? ;============================================================
? ? ? ? ;============ /End the scene
? ? ? ? ;============================================================
? ? .endif
? ? ;================================================================
? ? ;============ /Begin the scene
? ? ;================================================================
? ? ;================================================================
? ? ;============ Present the backbuffer contents to the display
? ? ;================================================================
? ? pcall lpd3dDevice.Present,0,0,0,0
? ? ;================================================================
? ? ;============ /Present the backbuffer contents to the display
? ? ;================================================================
? ? ret
Render endp
;********************************************************************
;**************** /Render
;********************************************************************
no zipfile upload in this forum????
It looks pretty much right.
TriangleStrips need to be constructed carefully, the vertex order is critical.
The Camera shouldn't be at -150 unless you have geometry there.
Try moving the camera position (hey, why not add keyboard controls to move it)
and also try rendering just a single triangle first.
Try disabling lighting, even though you have no lights.
I seem to remember that under Direct3D you need to set up a Material regardless, and that it needs to have ambient=1.0f, 1.0f, 1.0f, 1.0f but I'm only going from memory.
If NONE of that helps, I can post some working code, and you can find the difference yourself.
At this point, it's something really small.
Don't be discouraged, it took me over three months to get my first textured surfaces on screen.
After the teething problems, life gets easier.
After the teething problems, life gets easier.
hello daydreamer
You're outside the "Field of view" so your geometry isn't visible.
Keep your cam_vector.z below -100 (now it's -150) so it's in the Fov
? ? fpFar_Clipping_Plane? ? FLOAT 100.0f
? ? cam_vector? ? ? D3DXVECTOR3? <0.0f,0.0f,-50.f> ;move camera 50 back on the Z
? ? lookat_vector? ?D3DXVECTOR3? <0.0f,0.0f,0.0f>? ;look at the center of? Fov
Now your geometry must be visible.
You're outside the "Field of view" so your geometry isn't visible.
Keep your cam_vector.z below -100 (now it's -150) so it's in the Fov
? ? fpFar_Clipping_Plane? ? FLOAT 100.0f
? ? cam_vector? ? ? D3DXVECTOR3? <0.0f,0.0f,-50.f> ;move camera 50 back on the Z
? ? lookat_vector? ?D3DXVECTOR3? <0.0f,0.0f,0.0f>? ;look at the center of? Fov
Now your geometry must be visible.
I tested with Ligths,false changed camera z pos, looked at dx9 C++ sample and added a few texturetransform calls, when I added zbuffercode, my screen went from showing texture in 2d to blank
Post it all somewhere and I'll take a look :)
Post it all somewhere and I'll take a look :)
thanks, uploaded it to masm32 forum in laboratory
I can't see it .. maybe I'm looking in the wrong place?