Marcos Dell Antonio de Souza

Hi.

I'm using the MD3DM/Smartphone Emulator and trying to draw a triangle. The code is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.DirectX;
using Microsoft.WindowsMobile.DirectX.Direct3D;

namespace HelloWorld
{
public partial class Form1 : Form
{
private Device _device = null;
private VertexBuffer _verts = null;

/// <summary>
/// Main method
/// </summary>
static void Main()
{
Form1 form = new Form1();

// Initialize d3d
form.InitializeGraphics();

// Run
try
{
Application.Run(form);
}
catch (Exception ex)
{
MessageBox.Show("Erro ao iniciar a app: " + ex.Message);
}
}

/// <summary>
/// Prepare the d3d device
/// </summary>
private void InitializeGraphics()
{
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;

_device = new Device(0, DeviceType.Default, this, CreateFlags.None, presentParams);
_verts = CreateVertexBuffer();

_device.DeviceReset += new EventHandler(OnResetDevice);
OnResetDevice(_device, null);
}
catch (Exception ex)
{
MessageBox.Show("Erro na inicializacao: " + ex.Message);
}
}

/// <summary>
/// Handles device reset events
/// </summary>
private void OnResetDevice(object sender, EventArgs e)
{
//
}

/// <summary>
/// Called whenever the window needs to be repainted
/// </summary>
protected override void OnPaint(PaintEventArgs e)
{
// Render some stuff
Render();

// Invalidating the window will cause it to be redrawn in the future
Invalidate();
}

protected override void OnPaintBackground(PaintEventArgs e)
{
//
}

/// <summary>
/// Render some stuff
/// </summary>
private void Render()
{
// Clear the device
_device.Clear(ClearFlags.Target, Color.Bisque, 1.0f, 0);

// Render de scene
_device.BeginScene();

_device.SetStreamSource(0, _verts, 0);
_device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

_device.EndScene();
_device.Present();
}

/// <summary>
/// Create and return a VertexBuffer (triangle)
/// </summary>
private VertexBuffer CreateVertexBuffer()
{
CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];

verts[0] = new CustomVertex.TransformedColored(90.0f, 45.0f, 0.5F, 1, Color.Blue.ToArgb());
verts[1] = new CustomVertex.TransformedColored(45.0f, 160.0f, 0.5F, 1, Color.Green.ToArgb());
verts[2] = new CustomVertex.TransformedColored(145.0f, 160.0f, 0.5F, 1, Color.Red.ToArgb());

Pool vertexBufferPool;
Caps caps = _device.DeviceCaps;

if (caps.SurfaceCaps.SupportsVidVertexBuffer)
vertexBufferPool = Pool.VideoMemory;
else
vertexBufferPool = Pool.SystemMemory;


VertexBuffer buf =
new VertexBuffer(
typeof(CustomVertex.TransformedColored),
verts.Length,
_device,
0,
CustomVertex.TransformedColored.Format,
vertexBufferPool
);


GraphicsStream stm = buf.Lock(0, 0, 0);
stm.Write(verts);
buf.Unlock();


return buf;
}
}
}

I wrote this code looking at the MS samples to Pocket PCs. It's very seemed. Anybody knows why my triangle does not appear :-(

Thanks


Re: Game Technologies: DirectX 101 Why my triangle doesn't appear?

Marcos Dell Antonio de Souza

Hi man! I've got the solution.

I wrote a post about it: http://www.marcosdellantonio.net/blog/index.php/2007/02/14/md3dm-como-desenhar-um-tringulo-usando-o-smartphone-emulator/

Thanks and Bye.