Jump to content
  • Advertisement
Sign in to follow this  

Texturing error

This topic is 3626 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have created a program to draw a cube and paint a texture on it. But it paints only a tiny part of texture on whole face. Please suggest a correction. Imports System.Drawing Imports Microsoft.DirectX Imports Microsoft.DirectX.Direct3D Imports System Imports System.Windows.Forms Public Class Learn Dim device As Device Dim vb As VertexBuffer Dim tex As Texture Dim pp As New PresentParameters Dim pause As Boolean = False Dim mes As Mesh Dim texbox As Mesh Dim mat As Material Private Sub Learn_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Public Sub OnReset(ByVal sender As System.Object, ByVal e As System.EventArgs) device.RenderState.CullMode = Cull.None device.RenderState.Lighting = True device.RenderState.ZBufferEnable = True With device.Lights(0) .Type = LightType.Directional .Diffuse = Color.FromArgb(128, 128, 128) .Direction = New Vector3(0.5F, -0.33F, 0.66F) .Enabled = True .Update() End With tex = TextureLoader.FromFile(device, "c:\b.bmp") 'device.Lights(0).Type = LightType.Directional 'device.Lights(0).Diffuse = Color.White End Sub Public Sub OnCreate(ByVal sender As System.Object, ByVal e As System.EventArgs) 'vb = New VertexBuffer(GetType(CustomVertex.PositionNormalTextured), 100, device, Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Default) 'AddHandler vb.Created, New EventHandler(AddressOf OnVCreate) 'OnVCreate(vb, Nothing) mes = Mesh.Box(device, 2.0F, 2.0F, 2.0F) texbox = mes.Clone(mes.Options.Value, VertexFormats.Position Or VertexFormats.Normal Or VertexFormats.Texture0 Or VertexFormats.Texture1, device) Using vb As VertexBuffer = texbox.VertexBuffer Dim verts() As CustomVertex.PositionNormalTextured = DirectCast(vb.Lock(0, GetType(CustomVertex.PositionNormalTextured), LockFlags.None, texbox.NumberVertices), CustomVertex.PositionNormalTextured()) Dim i As Integer For i = 0 To verts.Length - 1 Step 4 verts(i).Tu = 0.0! verts(i).Tv = 0.0! verts(i + 1).Tu = 0.0! verts(i + 1).Tv = 1.0! verts(i + 2).Tu = 1.0! verts(i + 2).Tv = 1.0! verts(i + 3).Tu = 1.0! verts(i + 3).Tv = 0.0! Next vb.Unlock() End Using mat = New Material mat.Diffuse = Color.FromArgb(255, 255, 255) mat.Ambient = mat.Diffuse End Sub Public Sub OnVCreate(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Public Sub initgraph() pp.Windowed = True pp.SwapEffect = SwapEffect.Discard pp.EnableAutoDepthStencil = True pp.AutoDepthStencilFormat = DepthFormat.D24X8 'pp.BackBufferFormat = Format.X8B8G8R8 device = New Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, pp) AddHandler device.DeviceReset, New EventHandler(AddressOf OnReset) OnCreate(device, Nothing) OnReset(device, Nothing) pause = False End Sub Public Sub render() device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Blue, 1.0F, 0) device.BeginScene() SetupMatrices() With device .RenderState.Lighting = True .RenderState.Ambient = Color.FromArgb(64, 64, 64) End With device.Material = mat device.SetTexture(0, tex) mes.DrawSubset(0) device.EndScene() device.Present() End Sub Private Sub SetupMatrices() device.Transform.World = Matrix.RotationAxis(New Vector3(Math.Cos(Environment.TickCount / 250.0F), 1, Math.Sin(Environment.TickCount / 250.0F)), Environment.TickCount / 1000.0F) device.Transform.View = Matrix.LookAtLH(New Vector3(0.0F, 0.0F, -7.0F), New Vector3(0.0F, 0.0F, 0.0F), New Vector3(0.0F, 1.0F, 0.0F)) device.Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 4.0F, 1.0F, 1.0F, 100.0F) End Sub Private Sub Learn_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint render() End Sub End Class

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!