psychogeek

Hello,
I'm experimenting with a 2D space-shooter type of game and need to implement a starfield. To that end, what is the easiest way to draw a single pixel on the screen I'd like to be able to do this using normal (positive only) display coordinates (ie: 0,0 - 1024,768).

I'm not familiar with cameras/matrixes/transformations but I'm hoping I won't need all that just to do something as simple as this seems to be.

Thanks!
-newbie

### Re: XNA Game Studio Express 2D - Draw points on screen

Jim Perry

Take a look at this How To.

### Re: XNA Game Studio Express 2D - Draw points on screen

psychogeek

Thanks for the response.  I forgot to mention that I read that article and even toyed with the code for some time. The method it employs uses a 3D coordinate system and cameras/transformations/projections etc. Can't this be done without all of that added complexity

If not, is there a way to adjust the camera/view so that I can use a "normal" 2D coordinate system

TIA!
-newbie

### Re: XNA Game Studio Express 2D - Draw points on screen

a.d.m

If you are rendering a point list with a BasicEffect, set the world and view parameters to Matrix.Identity and then set the projection to Matrix.CreateOrthographic(). I forget the parameters, but basically you specify your min X, max X, min Y, and max Y and Z clipping. For your vertices, use VertexPositionColor and for the Z component of the position, set it to zero. All of your points will be drawn to the screen space that you specify in your orthographic projection. This method works for me.

### Re: XNA Game Studio Express 2D - Draw points on screen

Epsicode

The way I do it: (in a SpriteBatch)

for point:

draw a 1pixel texture with "1" as the scale factor.

for line:

calculate the line's angle and length, and draw a rotated one pixel texture with a Vec2D scale vector that is "length" long and 1 pixel wide (the rotation's angle is the line's angle).

### Re: XNA Game Studio Express 2D - Draw points on screen

Fluxtah

something like this

ScreenViewMatrix = Matrix.Identity;

Matrix.CreateOrthographicOffCenter(0, ScreenWidth, ScreenHeight, 0, 0.0f, 1.0f, out ScreenProjectionMatrix);

sorry its just a paste from one of my classes, but you get the idea.

### Re: XNA Game Studio Express 2D - Draw points on screen

a.d.m

Epsicode: that is a workable solution for situations where you don't need to draw too many, but psychogeek is talking about doing a starfield. If he wants 1000 stars, your method requires 1000 draw calls. If you use a VertexBuffer or an array of vertices, its just one draw call for all one thousand of them -- much less expensive.

### Re: XNA Game Studio Express 2D - Draw points on screen

Epsicode

I won't be expansive you use a SpriteBatch with Texture sorting mode, since it's always the same texture.

### Re: XNA Game Studio Express 2D - Draw points on screen

RivieraKid

its still a hack. Using a vertex buffer with a point list is the correct way.

### Re: XNA Game Studio Express 2D - Draw points on screen

Jim Perry

RivieraKid wrote:
 its still a hack. Using a vertex buffer with a point list is the correct way.

QFT. It's not difficult to do it this way. I'd suggest doing it.