I can't display a textured model.

Hi!

I have written a simple application using Directx9 with VB.Net 2003.

All I want to do is to display a very simple model (rectangle) with a texture added to it.

Unfortunately I can not do this properly. I can only get a black rectangle as a result (it is displayed at correct coordinates). Can anybody help me What is wrong Below you can find a sample of my code. I think, a bug is somewhere there.

Dim BuforWierzcholkow As VertexBuffer

BuforWierzcholkow = New VertexBuffer(UrzadzenieDX3D, 6 * CustomVertex.PositionTextured.StrideSize, Usage.None, CustomVertex.PositionTextured.Format, Pool.Default)

Dim Strumien = BuforWierzcholkow.Lock(0, 0, 0)

Dim Wierzcholki() As CustomVertex.PositionTextured = {New CustomVertex.PositionTextured(-1.0F, 1.0F, 1.0F, 0.0F, 0.0F), _

New CustomVertex.PositionTextured(-1.0F, -1.0F, 1.0F, 0.0F, 1.0F), _

New CustomVertex.PositionTextured(1.0F, 1.0F, 1.0F, 1.0F, 0.0F), _

New CustomVertex.PositionTextured(-1.0F, -1.0F, 1.0F, 0.0F, 1.0F), _

New CustomVertex.PositionTextured(1.0F, -1.0F, 1.0F, 1.0F, 1.0F), _

New CustomVertex.PositionTextured(1.0F, 1.0F, 1.0F, 1.0F, 0.0F)}

Strumien.Write(Wierzcholki)

BuforWierzcholkow.Unlock()

UrzadzenieDX3D.SetTexture(0, MyTexture)

UrzadzenieDX3D.SetStreamSource(0, BuforWierzcholkow, 0, CustomVertex.PositionTextured.StrideSize)

UrzadzenieDX3D.VertexFormat = CustomVertex.PositionTextured.Format

UrzadzenieDX3D.DrawPrimitives(PrimitiveType.TriangleList, 0, 2)

I did some kind of test and I changed format of my vertices to CustomVertex.PositionColored and set the color to red, but I still get the same effect (black rectangle).

Thank you

Karlo



Answer this question

I can't display a textured model.

  • Whitespace

    No, I didn't do anything with TextureState.

    BTW: I don't know if this problem regards only texturing. As I wrote above I can't render colored model too (after changing some parts of my code to use CustomVertex.PositionColored).


  • PhilMossop

    You define your vertex position in the wrong order
    (not the texture coordinate, the position)
    Instead of -1,1 // -1,-1 // 1,1
    Try this:
    -1,1 // 1,1 // -1,-1

    When you do this it's like drawing a round arrow on top of your face
    The arrow should point like a clock rotation

    if this doesn't work this link may help you : (don't forget to set light if you use it)

    http://www.toymaker.info/Games/html/invisible_geometry.html

    Correct Winding - you must define your triangles by specifying vertex in clockwise order. This is essential because internally Direct3D knows that if the winding is counter clockwise the triangle must be facing away from the camera and so does not need rendering. Normally this is great as it speeds things up but if you have accidentally defined your vertex in the wrong order it will mean you will see nothing. Remember to define the clockwise order in terms of looking at the face head on. If baffled create an object out of paper and label it, then rotate it to see the correct vertex order.


  • CaleDB

    Now I know, what is wrong. I should turn off the lighting. I have no functions to handle lights in my code, so I should turn it off to use colors provided by the object. If I don't do this DirectX will try to use lights, probably fail and show black (default) object.

    Thanks to all.

    Karlo


  • keiichi76537

    Have you changed the setup of the pixel function

    Somthing like:

    device.TextureState[0].ColorOperation = TextureOperation.SelectArg1

    device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor

    device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1

    device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor



  • I can't display a textured model.