Preface
Before we get started, I want to preface about this guide! First thing I want to preface is
that I am NOT a teacher/professor, a CS major, or have decades of experience with programming!
So in turn my code isn't going to be perfect by any means, however I understand my code (for the most part);
I also don't use any sort of LLMs (as you can probably tell lol with my grammar) for programming or writing!
Yeah, I want to be a primary care physician for cripe’s sake, I enjoy programming/writing as a hobby, but I
really don't think I could do this for a living (plus I have way more enjoyment as a doctor)! Maybe a side-gig,
but not a career!
The second thing I want to preface is you do you, woman/man/enby! Yes my code DOES use MonoGame, but you can use anything to display pixels! You can use for example SILK.NET or OpenTK to display pixels! MonoGame is rather large, and we don't really need full sprites or the Content Manager for this project, I just used MonoGame because I know it (heck I probably will make a SILK.NET version of this)!
The second thing I want to preface is you do you, woman/man/enby! Yes my code DOES use MonoGame, but you can use anything to display pixels! You can use for example SILK.NET or OpenTK to display pixels! MonoGame is rather large, and we don't really need full sprites or the Content Manager for this project, I just used MonoGame because I know it (heck I probably will make a SILK.NET version of this)!
What This Guide Is
Why?
What Is An BMP?
Getting Started
Let's Get Pixelacle!
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace MonoBMP;
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
base.Initialize();
}
protected override void LoadContent()
{
base.LoadContent();
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
}
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace MonoBMP;
public class Screen
{
// Screen Properties
public int _imageWidth = 0;
public int _imageHeight = 0;
// Misc
public Color[,] pixelStates;
// Classes
public GraphicsDeviceManager _graphics;
public ContentManager _contentManager;
// Pixel
public Texture2D pixel;
public Screen(int imageWidth, int imageHeight,
GraphicsDeviceManager graphics, ContentManager contentManager)
{
// Set Classes
_graphics = graphics;
_contentManager = contentManager;
// Set Display
_imageHeight = imageHeight;
_imageWidth = imageWidth;
_graphics.PreferredBackBufferHeight = _imageHeight;
_graphics.PreferredBackBufferWidth = _imageWidth;
_graphics.ApplyChanges();
// Set Pixels
pixelStates = new Color[_imageHeight, _imageWidth];
Clear(); // this will set all pixels to a value so we dont null!
}
public void LoadContent()
{
pixel = new Texture2D(_graphics.GraphicsDevice, 1, 1);
pixel.SetData(new[] { Color.White });
}
public void Clear()
{
for (int y = 0; y < _imageHeight; y++)
{
for (int x = 0; x < _imageWidth; x++)
{
pixelStates[y, x] = new Color(255,255,255);
}
}
}
public void ReSizeWindowSize(int height, int width)
{
var previousWidth = _imageWidth;
var previousHeight = _imageHeight;
_imageWidth = width;
_imageHeight = height;
_graphics.PreferredBackBufferHeight = _imageHeight;
_graphics.PreferredBackBufferWidth = _imageWidth;
_graphics.ApplyChanges();
var previousPixelStates = pixelStates;
pixelStates = new Color[height, width];
Clear();
}
public void SetPixel(int y, int x, Color colour)
{
if (y < _imageHeight)
{
if (x < _imageWidth)
{
pixelStates[y, x] = colour;
}
}
}
public void Draw(SpriteBatch spriteBatch)
{
for (int y = 0; y < _imageHeight; y++)
{
for (int x = 0; x < _imageWidth; x++)
{
spriteBatch.Draw(pixel, new Rectangle(x, y, 1, 1), pixelStates[y,x]);
}
}
}
}
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace MonoBMP;
public class Game1 : Game
{
// Classes
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private Screen _screen;
// Window/Image/Screen Size & Such
private int screenWidth = 500;
private int screenHeight = 500;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
_screen = new Screen(screenWidth, screenHeight, _graphics, Content);
_screen.SetPixel(10, 10, Color.Red);
base.Initialize();
}
protected override void LoadContent()
{
_screen.LoadContent();
base.LoadContent();
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
_spriteBatch.Begin();
_screen.Draw(_spriteBatch);
_spriteBatch.End();
base.Draw(gameTime);
}
}
It Takes Some Bits To Shrek!
STUB
Displaying/Parsing The Bits/Bytes For Shrek!