Skip to content

Hello World

Javidx9 edited this page Apr 16, 2020 · 2 revisions

Example olcPixelEngine "Hello World"

The code below is a starting "skeleton" for all olc::PixelGameEngine applications. It produces a colourful noisy sequence of pixels. The PGE is constructed as being a 256x240 display, where each PGE pixel is 4x4 screen pixels (providing the application is not resized - if it is, then the aspect ratio will be maintained).

#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"

class Example : public olc::PixelGameEngine
{
public:
	Example()
	{
		sAppName = "Example";
	}

public:
	bool OnUserCreate() override
	{
		// Called once at the start, so create things here
		return true;
	}

	bool OnUserUpdate(float fElapsedTime) override
	{
		// called once per frame
		for (int x = 0; x < ScreenWidth(); x++)
			for (int y = 0; y < ScreenHeight(); y++)
				Draw(x, y, olc::Pixel(rand() % 256, rand() % 256, rand()% 256));	
		return true;
	}
};


int main()
{
	Example demo;
	if (demo.Construct(256, 240, 4, 4))
		demo.Start();

	return 0;
}