|
Use a more descriptive subject line next time
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi there ,
I'm trying to develop a ray tracing software in c++ by the help of "Ray Tracing from ground up" book by Kevin Suffern.
Here is a sample of the program :
World::render_scene(void) {
RGBColor pixel_color;
Ray ray;
double zw = 100.0;
double x,y;
open_window(vp.hres,vp.vres);
ray.d = Vector3D(0,0,-1);
for ( int r = 0;r< vp.vres;r++)
for (int c = 0;c<=vp.hres;c++){
x = vp.s * (c - 0.5 * (vp.hres - 1.0));
y = vp.s * (r - 0.5 * (vp.vres - 1.0));
ray.o = Point3D(x,y,zw) ;
pixel_color = tracer_ptr->trace_ray(ray);
display_pixel(r,c,pixel_color);
}
}
My question is what to write inside open_window body and also display_pixel in order to create a window that contain an image .
Regards ,
Ahmad
|
|
|
|
|
Okay, here it goes...
[My rant]
I've been searching for weeks now on how to work with 2D images in DirectX using C#. However, I've been completely unsuccessful in doing so. The help files that come with DirectX are horrible because they are organized by classes and such. Meaning that a person like me who has never worked with DirectX before, will be completely lost. The help files should take you through DirectX in order of complexity, showing you the simplest things first, but they don't. They are more like a reference guide. But, anyways they are no help to DirectX newbies like me.
I've looked around on the internet a lot trying to get some information on this topic and then attempting to piece it together. However, I've been completely unsuccessful. 90% of all examples are using out-dated versions of DirectX, meaning they are irrelevant to me. The other 10% are either in C++, which I do not understand.
I've seen some rare occurrences of 2D DirectX projects in C#, but they are using older versions of C#, which didn't fully support DirectX and were workarounds (so they've said). When I try to convert them to the newest version of a C# solution they fail to compile.
There is a sample that comes with DirectX that supposed to show you how to perform "Simple 2D". However, it actually not very simple and is a rather large project in my world. But, the killer is that it also fails to run on my computer, most likely because they are trying to use some advanced feature when its supposed to be "Simple 2D". I'm pretty sure my computer is capable of displaying some 2D images and then move them around a little.
[/My rant]
So that's enough of my complaining, I just wanted anyone who reads this thread to know that I did try to figure this out on my own before coming here.
Basically what I'm asking for is for someone to either explain to me very simply how to get a basic 2D C# project using DirectX up and running or create one for me so I can pick it apart and try to figure out what's going on.
I only want the simplest example. Like displaying some 2D images and maybe moving them around or rotating them. Nothing fancy.
Many thanks in advance to anyone who can help me out. 
|
|
|
|
|
I still need help on this topic, but to make it easier for someone to help me I put together a project myself. However, it should be working, but its not; The image never shows up on the form.
Here's the link to the project files:
http://www.freewebs.com/thrash505/2D_DirectX9_Test.zip
Program.cs
#region Using Directives
using System;
using System.Windows.Forms;
#endregion
namespace _2D_DirectX9_Test {
#region Program Class
public static class Program {
[STAThread]
public static void Main( ) {
GameForm gameForm = new GameForm( );
gameForm.Show( );
while( gameForm.Created ) {
gameForm.RenderGraphics( );
Application.DoEvents( );
}
}
}
#endregion
}
GameForm.cs
#region Using Directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
#endregion
namespace _2D_DirectX9_Test {
#region GameForm Class
public partial class GameForm : Form {
#region GameForm - Attributes
private Device _graphicsDevice;
private Sprite _spriteManager;
private GraphicsSprite gs;
#endregion
#region GameForm - Properties
private Device GraphicsDevice {
get { return _graphicsDevice; }
set { _graphicsDevice = value; }
}
private int ScreenWidth {
get { return 1024; }
}
private int ScreenHeight {
get { return 768; }
}
public Sprite SpriteManager {
get { return _spriteManager; }
set { _spriteManager = value; }
}
#endregion
#region GameForm - Constructors
public GameForm( ) {
InitializeComponent( );
InitializeGraphics( );
}
#endregion
#region GameForm - Methods
private void InitializeGraphics( ) {
PresentParameters presentParameters = new PresentParameters( );
Format currentFormat = Manager.Adapters[ 0 ].CurrentDisplayMode.Format;
presentParameters.SwapEffect = SwapEffect.Discard;
if( Manager.CheckDeviceType( 0, DeviceType.Hardware, currentFormat, currentFormat,
false ) ) {
presentParameters.Windowed = true;
presentParameters.BackBufferFormat = currentFormat;
presentParameters.BackBufferCount = 1;
presentParameters.BackBufferWidth = ScreenWidth;
presentParameters.BackBufferHeight = ScreenHeight;
} else {
presentParameters.Windowed = true;
}
GraphicsDevice = new Device( 0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParameters );
SpriteManager = new Sprite( GraphicsDevice );
gs = new GraphicsSprite( new Vector3( 0f, 0f, 1f ),
TextureLoader.FromFile( GraphicsDevice, @"C:\music_player.png" ) );
}
public void RenderGraphics( ) {
_spriteManager.Begin( SpriteFlags.AlphaBlend );
gs.Draw( SpriteManager );
_spriteManager.End( );
}
private void GameForm_KeyUp( object sender, KeyEventArgs e ) {
if( e.KeyCode == Keys.Escape )
this.Close( );
}
#endregion
}
#endregion
}
GraphicsSprite.cs
#region Using Directives
using System;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
#endregion
namespace _2D_DirectX9_Test {
#region GraphicsSprite Class
public class GraphicsSprite {
#region GraphicsSprite - Attributes
private Vector3 _center;
private Vector3 _position;
private Rectangle _sourceRectangle;
private Texture _texture;
#endregion
#region GraphicsSprite - Properties
public Vector3 Center {
get { return _center; }
set { _center = value; }
}
public Vector3 Position {
get { return _position; }
set { _position = value; }
}
public Rectangle SourceRectangle {
get { return _sourceRectangle; }
set { _sourceRectangle = value; }
}
public Texture Texture {
get { return _texture; }
set { _texture = value; }
}
#endregion
#region GraphicsSprite - Constructors
public GraphicsSprite( Vector3 position ) {
Center = new Vector3( 0, 0, 0 );
Position = position;
}
public GraphicsSprite( Vector3 center, Vector3 position ) {
Center = center;
Position = position;
}
public GraphicsSprite( Vector3 center, Vector3 position, Texture texture ) {
SurfaceDescription surfaceDescription;
Center = center;
Position = position;
Texture = texture;
surfaceDescription = Texture.GetSurfaceLevel( 0 ).Description;
SourceRectangle = new Rectangle( 0, 0, surfaceDescription.Width,
surfaceDescription.Height );
}
public GraphicsSprite( Vector3 position, Texture texture ) {
SurfaceDescription surfaceDescription;
Center = new Vector3( 0, 0, 0 );
Position = position;
Texture = texture;
surfaceDescription = Texture.GetSurfaceLevel( 0 ).Description;
SourceRectangle = new Rectangle( 0, 0, surfaceDescription.Width,
surfaceDescription.Height );
}
#endregion
#region GraphicsSprite - Methods
public void Draw( Sprite spriteManager ) {
spriteManager.Draw( Texture, SourceRectangle, Center, Position, Color.White );
}
#endregion
#endregion
}
}
Thanks again to anyone who can help me.
|
|
|
|
|
 I've finally figured out why my code wasn't working... I had to set the view transform and turn off lighting. Then I had to put in the BeginScene(), EndScene(), and Present() calls when rendering.
Here's the new version of the GameForm.cs file:
#region Using Directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
#endregion
namespace _2D_DirectX9_Test {
#region GameForm Class
public partial class GameForm : Form {
#region GameForm - Attributes
private Device _graphicsDevice;
private Sprite _spriteManager;
private GraphicsSprite gs;
#endregion
#region GameForm - Properties
private Device GraphicsDevice {
get { return _graphicsDevice; }
set { _graphicsDevice = value; }
}
private int ScreenWidth {
get { return 1024; }
}
private int ScreenHeight {
get { return 768; }
}
public Sprite SpriteManager {
get { return _spriteManager; }
set { _spriteManager = value; }
}
#endregion
#region GameForm - Constructors
public GameForm( ) {
InitializeComponent( );
InitializeGraphics( );
}
#endregion
#region GameForm - Methods
private void InitializeGraphics( ) {
PresentParameters presentParameters = new PresentParameters( );
Format currentFormat = Manager.Adapters[ 0 ].CurrentDisplayMode.Format;
presentParameters.SwapEffect = SwapEffect.Discard;
if( Manager.CheckDeviceType( 0, DeviceType.Hardware, currentFormat, currentFormat,
false ) ) {
presentParameters.Windowed = true;
presentParameters.BackBufferFormat = currentFormat;
presentParameters.BackBufferCount = 1;
presentParameters.BackBufferWidth = ScreenWidth;
presentParameters.BackBufferHeight = ScreenHeight;
} else {
presentParameters.Windowed = true;
}
GraphicsDevice = new Device( 0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParameters );
GraphicsDevice.Transform.View = Matrix.OrthoOffCenterLH( 0, ScreenWidth, ScreenHeight, 0, 0, 10 );
GraphicsDevice.RenderState.Lighting = false;
SpriteManager = new Sprite( GraphicsDevice );
gs = new GraphicsSprite( new Vector3( 0f, 0f, 1f ),
TextureLoader.FromFile( GraphicsDevice, @"C:\test.bmp" ) );
}
public void RenderGraphics( ) {
GraphicsDevice.Clear( ClearFlags.Target, Color.FromArgb( 0, 0, 225 ), 0, 0 );
GraphicsDevice.BeginScene( );
_spriteManager.Begin( SpriteFlags.AlphaBlend );
gs.Draw( SpriteManager );
_spriteManager.End( );
GraphicsDevice.EndScene( );
GraphicsDevice.Present( );
}
private void GameForm_KeyUp( object sender, KeyEventArgs e ) {
if( e.KeyCode == Keys.Escape )
this.Close( );
}
#endregion
}
#endregion
}
Hopefully that will help somebody else.
|
|
|
|
|
Hi,
After having drawn a lot to a Graphics object ( DrawString, DrawImage, FillRectangle etc ) I want to get at the "big picture".
I was hoping for a graphicsObject.GetImage()
All I want to do is to display the "big picture" on screen i.e. a print preview but where I can get at the bitmap.
Thanks
|
|
|
|
|
Hi,
in .NET using GDI+ it would be the other way around: you can get the Graphics for an
Image (such as a Bitmap) by calling the Graphics.FromImage method, so the way to do it would be:
- create an Image (Bitmap) of sufficient size
- get its Graphics
- use its Graphics to create/modify the image content
- now use the image in any way you see fit (either Paint it on screen, print it, or save it).
|
|
|
|
|
I downloaded the DirectX 9.0c SDK (C#) from the Microsoft site and then installed it.
After that I wanted to compile a sample C# source and discovered that the References to DirectX were not available!
How do I get the DirectX assemblies on my PC so that I can use DirectX namespace(s)?
Do I need to download and install some more software for this? What do I need and where do I get it from?
Please some advice.
Thank you, Ranger.
|
|
|
|
|
It turned out I had only installed the DirectX SDK and not the runtime library.
It seems that new books about DirectX (like version 10) no longer use the C# programming language but use the C++ language instead.
From what I have read about DirectX I figure it is much more complicated than OpenGL, so I will stick to the latter...
Ranger.
|
|
|
|
|
Haha, sorry, I couldn't resist. I could use some guides to common graphics techniques, e.g. selecting by colour, making a flat round button look '3d' by gradienting its edges, etc. I've been given some example images that are plain line drawings, and I need to add some pizzaz, enough to avoid breaking budget by hiring a designer. I'll be using either the Gimp or Paint.NET, and Expression Web and Blend.
moved on Friday, July 18, 2008 7:44 AM
|
|
|
|
|
|
Not quite what I had in mind, but amazingly cool. Thanks!
I was thinking more along the lines of using images as buttons, probably implemented as ImageButton controls, but I'm sure if I get halfway with the image, and place it on a cool, glassy button, I'll have a winner.
|
|
|
|
|
Graham's site suggestion looks cool. I'd use that.
When I had to draw some nice looking buttons a while back (I used WPF to generate them - I find typing easier than drawing ), I based what I did from several of these tutorials[^]. they give you an idea what kind of shapes and gradients you need to build up a good 3d squishy/glassy look with highlights and stuff, and you just improvise a bit from there.
Simon
|
|
|
|
|
I do remember a site that analyzes how Vista Aero stuff is drawn on a pixed/shade/line level. Can#t find it anymore, though.
at least I found this[^]
Also, the Windows User Interface guidelines have at least some material about it.
The linked site seems to have way more of it[^]
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighist
|
|
|
|
|
Try meby this : www.pixel2life.com
What I normally do when i need to make my app "pimp" - is to screenshot few fancy sites or apps and crate a unique look and feel in paint... then reduce the size of the bitmaps in Gimp 
|
|
|
|
|
Hi
I am working on project related to optimal travelling solution.
i have to draw map of world on computer screen using latitude and longitude.
Can someone help me regarding this problem?????
Thanx
|
|
|
|
|
aadilali wrote: I am working on project related to optimal travelling solution.
http://en.wikipedia.org/wiki/Great-circle_distance[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
|
|
|
|
|
what do you mean by this?????
|
|
|
|
|
the shortest distance between two points on a map representing the globe (latitude and longitude) is through great circle distances. If you are plotting any kind of traveling solution, the optimal path is via the great-circle calculation.
|
|
|
|
|
Hi!
I am a new in DirectX ver. 9.0.
How can I draw a 3d circle? Please help me
|
|
|
|
|
First, learn to draw a 2D point...
(a circle is a 2-dimensional shape, by definition it exists on a single plane. Are you asking for a sphere?)
Citizen 20.1.01 'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
|
|
|
|
|
Exactly I want to draw a wheel whose inner portion has nothing.
|
|
|
|
|
|
If you want to rotate or tilt the wheel (or alter the view perspective) you probably want to create a mesh and texture it. This is tedious stuff to code, and many programmers use an Auto-CAD program to create the mesh file. A wheel wouldn't be that difficult to code, but programatically applying the texture so that it looks professional is not a trivial task.
If, however, the wheel isn't going to move (tilt or rotate), creating a static image and just displaying it as a texture would be alot easier.
To give you an idea of how to create a mesh, see this Tutorial on Creating a Mesh (Managed DirectX)[^]
|
|
|
|
|
|