Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 23rd, 2007, 06:08 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default textureing by a bmp file.


hi.
i have creat a flat earth by below code.
but it s withe.
i wan t to texture it by a bmp file.
i don t khow how i can do it.
please help me.
thanks.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Drawing;
namespace Directx1
{
    class GameEngine
    {
        private GraphicInitiator graphicInit;
        private Device device3d;
        private Form1 form;
        private VertexBuffer vb;
        private short[] indices;//andis ha ra neshan midahad
        private IndexBuffer ib;
        private int WIDTH = 100;//arz
        private int HEIGHT = 100;
        private int[,] heightData;//ertefa
        private CustomVertex.PositionColored[] vertices;//noghat ra neshan khahad dad


        private void IndicesDeclaration()
        {//dar index bafeer andis haman ra set khahim kard
            ib = new IndexBuffer(typeof(short), (WIDTH - 1) * (HEIGHT - 1) * 6, device3d, Usage.WriteOnly, Pool.Default);
            indices = new short[(WIDTH - 1) * (HEIGHT - 1) * 6];

            for (int x = 0; x < WIDTH - 1; x++)
            {

                for (int y = 0; y < HEIGHT - 1; y++)
                {
                    indices[(x + y * (WIDTH - 1)) * 6] = (short)((x + 1) + (y + 1) * WIDTH);
                    indices[(x + y * (WIDTH - 1)) * 6 + 1] = (short)((x + 1) + y * WIDTH);
                    indices[(x + y * (WIDTH - 1)) * 6 + 2] = (short)(x + y * WIDTH);

                    indices[(x + y * (WIDTH - 1)) * 6 + 3] = (short)((x + 1) + (y + 1) * WIDTH);
                    indices[(x + y * (WIDTH - 1)) * 6 + 4] = (short)(x + y * WIDTH);
                    indices[(x + y * (WIDTH - 1)) * 6 + 5] = (short)(x + (y + 1) * WIDTH);
                }
            }
            ib.SetData(indices, 0, LockFlags.None);
        }
        private void LoadHeightData()
            //heath data z ra bara ma moshakhas mikonad
        {
            heightData = new int[WIDTH, HEIGHT];
            for (int x = 0; x < WIDTH; x++)
            {
                for (int y = 0; y < HEIGHT; y++)
                {
                    heightData[x ,y]=0;
                    heightData[x ,y]=0;
                    heightData[x, y] = 0;
                }
            }
            //heightData[WIDTH / 2, HEIGHT / 2] = 5;
        }







        public GameEngine(Form1 Frm)
        {
            form = Frm;
            graphicInit = new GraphicInitiator();//peykar bandi device
            graphicInit.initDevice(ref device3d, form);
            LoadHeightData();//hamashon sefran
            VertexDeclaration();
            IndicesDeclaration();
            CameraPositioning();
        }

        public void clear()
        {

            device3d.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0);

        }
        private void CameraPositioning()
        {
            device3d.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, form.Width / form.Height, 1f, 300f);
            device3d.Transform.View = Matrix.LookAtLH(new Vector3(0, -50, 15), new Vector3(0, 0, 0), new Vector3(0, 0, 1));
            device3d.RenderState.Lighting = false;
            device3d.RenderState.CullMode = Cull.None;

        }

private void VertexDeclaration()
{//be andaze tool * arze zamin noghte tarif kardim
    vb = new VertexBuffer(typeof(CustomVertex.PositionColored), WIDTH*HEIGHT, device3d, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);
    vertices = new CustomVertex.PositionColored[WIDTH*HEIGHT];

    for (int x=0;x< WIDTH;x++)
    {
        for (int y=0; y< HEIGHT;y++)
        {
            vertices[x+y*WIDTH].Position = new Vector3(x, y, 0);
            vertices[x+y*WIDTH].Color = Color.White.ToArgb();
            vertices[x + y * WIDTH].Position = new Vector3(x, y, heightData[x, y]);
        }
    }

    vb.SetData(vertices, 0 ,LockFlags.None);
}


      public void drawWorld()
        {
            CameraPositioning();
            device3d.BeginScene();
          device3d.Transform.World=Matrix.Translation(new Vector3(-50,5,-20));
            device3d.VertexFormat = CustomVertex.PositionColored.Format;
            device3d.SetStreamSource(0, vb, 0);
            device3d.Indices = ib;
            device3d.DrawIndexedPrimitives(PrimitiveType.Trian gleList, 0, 0, WIDTH * HEIGHT, 0, indices.Length / 3);
            device3d.EndScene();
            device3d.Present();
        }
    }
}
    Report to moderator

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
convert Image(jpeg/bmp,etc) file into binary forma venkat2reddy C# 2 September 14th, 2010 07:58 AM
php form for up-loading a gif., jpg, or bmp file Wilbon Beginning PHP 2 January 8th, 2006 09:32 AM
VB and BMP file manipulation. xorprime Beginning VB 6 1 March 2nd, 2005 01:59 PM
BMP Iamges shs BOOK: Beginning ASP.NET 1.0 1 August 31st, 2004 05:34 PM
Exception while running BMP ramko J2EE 0 August 5th, 2003 05:27 AM



All times are GMT -4. The time now is 04:46 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.