Git Product home page Git Product logo

olcpixelgameengine's Introduction

Hang on! I'm looking for Javidx9's video source code! It's moved here: https://github.com/OneLoneCoder/Javidx9

Shameless Promotion

There is a feature rich and working fork of this repo aimed at Android & IOS development: https://github.com/Johnnyg63/OLCPGEMobileVisualStudio

olcPixelGameEngine

The official distribution of olcPixelGameEngine, a tool used in javidx9's YouTube videos and projects.

You only need the one file - olcPixelGameEngine.h - included in your project!

Provides a fast, richly featured, cross platform pixel drawing and user interface framework for

  • The development of games
  • Visualisation of algorithms
  • Prototyping and experimentation
  • Education

olcPixelGameEngine is easily extended! for example:

  • 2D Affine transforms
  • 3D Software renderer
  • Controller input
  • Sound
  • Hardware interfaces

olcPixelGameEngine is easy to port! Runs on:

  • Windows (all)
  • Linux / Raspberry Pi / ChromeOS
  • MacOS (coming soon to official, but already available in "Contributors")
  • PSP & Switch (Not supported by OneLoneCoder)

olcPixelGameEngine has been reimplemented in other languages!

  • C#
  • Rust
  • Lua
  • Java

olcPixelGameEngine is actively maintained and developed!

olcPixelGameEngine is used by 100s, if not 1000s of programmers at all levels of ability!

Documentation

Please see https://github.com/OneLoneCoder/olcPixelGameEngine/wiki

License (OLC-3)

Copyright 2018 - 2024 OneLoneCoder.com

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions or derivations of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions or derivative works in binary form must reproduce the above copyright notice. This list of conditions and the following disclaimer must be reproduced in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

olcpixelgameengine's People

Contributors

explorer1 avatar gusgo99 avatar moros1138 avatar onelonecoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

olcpixelgameengine's Issues

Arbitrary crash of sound mixing

I'm using the OLC Pixel Game Engine, with sounds, in my game Altay Tank Game.

Recently, with game v1.0, I've started to receive some bug reports saying that the game sometimes halts (stops responding) without a total crash. I've also come across a similar situation when I was running through Visual Studio, Release build.

In my experience the following lines were highlighted (specifically add to the mix line):

else
	{
		// Calculate sample position
		s.nSamplePosition += (long)((float)vecAudioSamples[s.nAudioSampleID - 1].wavHeader.nSamplesPerSec * fTimeStep);
		// If sample position is valid add to the mix
		if (s.nSamplePosition < vecAudioSamples[s.nAudioSampleID - 1].nSamples)
			fMixerSample += vecAudioSamples[s.nAudioSampleID - 1].fSample[(s.nSamplePosition * vecAudioSamples[s.nAudioSampleID - 1].nChannels) + nChannel];
	else

Just wondering if this is a Windows sound mixing issue, and I'd like to know if there's a Best Practice I might be missing. I'm roughly guessing that this halt might occur when several sounds are being mixed and played simultaneously.

My game source code is available on Github: https://github.com/gurkanctn/AltayTankGame/blob/master/Altay.cpp

Thanks for any tips and suggestions or a fix.

Greetings,

Backbuffer does not get cleared on Win7 64bit

Backbuffer does not get cleared tested on Win7 and Win10 64bit. So it looks like the old stuff that has been drawn does not get cleared after swapping buffers.

In olcPixelGameEngine.h line 1962 there is the WinApi call to SwapBuffers(glDeviceContext);
However this does not work properly on Win7 somehow. Although SwapBuffers returns true (tested it), it does not work.
I checked msdn for SwapBuffers and it says: If the current pixel format for the window referenced by the device context does not include a back buffer, this call has no effect and the content of the back buffer is undefined when the function returns. With multithread applications, flush the drawing commands in any other threads drawing to the same window before calling SwapBuffers.
Probably the issue comes from there.

issue

olcPGEX_Graphics3D.h missing #include?

olcPGEX_Graphics3D.h: In static member function ‘static void olc::GFX3D::ClearDepth()’: olcPGEX_Graphics3D.h:953:84: error: ‘memset’ was not declared in this scope memset(m_DepthBuffer, 0, pge->ScreenWidth() * pge->ScreenHeight() * sizeof(float));
This is solved by adding #include<cstring> to the file. Not sure if this is a Linux specific thing or not? I almost never do anything C/C++ any more, and never in Windows :)

Any unmapped key is interpreted as key A

When user presses alt key in PGE application the key press is mapped as olc::Key::A. This seems to be caused by behaviour of map data structure in standard library. The documentation of std::map::operator[] says "If k does not match the key of any element in the container, the function inserts a new element with that key and returns a reference to its mapped value." In this case the value is the value seems to be the first element of enum olc::Key, which is A.

This problem could be solved with starting olc::Key with not used element ie. NONE.

This bug is also case of the issue #2

the boundary-Pixels of Sprite::Sample and `Sprite::SampleBL` are computed wrong

Sprite::Sample can receive values for x and y which are 0 or 1 (or lower or higher)
this can result in the edges of a sprite being sampled out of bounds.
the change form 1.12 to 1.13 of shiftig by half a pixel has fixed the edge case of value 1, but shifted the whole sprite by half a pixel:

left 1.13, right my proposed solution:
pgesamplewrong

as for Sprite::SampleBL the problem is about the same, but the initial u and v are being rounded in the wrong direction for very small values of u and v. if u and v are negative the cast rounds up to zero. explicitly using floorfixes the issues shown below.
then the same usage of min and max will allow access to color-values out of bounds.

left 1.13, right my proposed solution:
pgesampleblwrong

the image shown is always the same of size 5x5 .

Fonts are really big

I was following your spline tutorial (good tutorial by the way) and found that the fonts are rendered much bigger that what the olcConsoleGameEngine outputs in your tutorial.

Example code

using namespace std;

#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
    {
        float x = 80.f, y = 40.f;
        DrawRect(x - 1, y - 1, 2, 2);
        DrawString(x, y, to_string(3));
        return true;
    }
};

int main()
{
    Example demo;
    if (demo.Construct(160, 80, 10, 10))
        demo.Start();

    return 0;
}

Screenshot
image

(Solved) Unresolved external symbols.

[SOLVED]
I solved this issue by defining OLC_PGE_APPLICATION.
I'll leave the issue down there tho.


Hello,

I've been trying to create my first project using PixelGameEngine to try it and see what I can do with it.
Unfortunately, when compiling on Visual Studio 2017, I've got unresolved external symbols.

Here's the code:
image

And here's the output (sorry, it's in french but I hope you get the essential):
image

How can I fix this?

(Btw, I love your channel, keep it up dude!)

ERROR: use of deleted function 'olc::ResourcePack::sEntry::sEntry(olc::ResourcePack::sEntry&&)' auto streamBuffer = pack->GetStreamBuffer(sImageFile);

Hi there,
First thanks for the hard work that has been done to assemble this delicious game engine!
i got an issue after i changed my compiler from the visual studios to MinGW.
although it was working fine with the visual studio compiler (#undef "if it works, don't touch it")
not sure if i am doing something wrong here or there is a bug.
here are the details of this issue.
Thanks once again for the great work!!!

OneLoneCoder Pixel Game Engine v1.20 
Windows10 64bit
Compiler:  MinGW64 3.4 | GDB 7.8.1
IDE: CLion 2019.2.3 64bit
====================[ Build | FlappyBird | Debug ]==============================
"C:\Program Files\JetBrains\CLion 2019.2.3\bin\cmake\win\bin\cmake.exe" --build C:\Users\bader\Desktop\FlappyBird\cmake-build-debug --target FlappyBird -- -j 1
[ 50%] Building CXX object CMakeFiles/FlappyBird.dir/main.cpp.obj
In file included from C:\Users\bader\Desktop\FlappyBird\main.cpp:2:0:
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h: In member function 'olc::rcode olc::Sprite::LoadFromPGESprFile(std::string, olc::ResourcePack*)':
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:745:56: error: use of deleted function 'olc::ResourcePack::sEntry::sEntry(olc::ResourcePack::sEntry&&)'
    auto streamBuffer = pack->GetStreamBuffer(sImageFile);
                                                        ^
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:341:10: note: 'olc::ResourcePack::sEntry::sEntry(olc::ResourcePack::sEntry&&)' is implicitly deleted because the default definition would be ill-formed:
   struct sEntry : public std::streambuf {
          ^
In file included from E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/ios:43:0,
                 from E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/ostream:38,
                 from E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/iostream:39,
                 from C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:224,
                 from C:\Users\bader\Desktop\FlappyBird\main.cpp:2:
E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/streambuf:802:7: error: 'std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits]' is private
       basic_streambuf(const basic_streambuf& __sb)
       ^
In file included from C:\Users\bader\Desktop\FlappyBird\main.cpp:2:0:
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:341:10: error: within this context
   struct sEntry : public std::streambuf {
          ^
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h: In member function 'olc::rcode olc::ResourcePack::AddToPack(std::string)':
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:980:19: error: use of deleted function 'olc::ResourcePack::sEntry& olc::ResourcePack::sEntry::operator=(const olc::ResourcePack::sEntry&)'
   mapFiles[sFile] = e;
                   ^
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:341:10: note: 'olc::ResourcePack::sEntry& olc::ResourcePack::sEntry::operator=(const olc::ResourcePack::sEntry&)' is implicitly deleted because the default definition would be ill-formed:
   struct sEntry : public std::streambuf {
          ^
In file included from E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/ios:43:0,
                 from E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/ostream:38,
                 from E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/iostream:39,
                 from C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:224,
                 from C:\Users\bader\Desktop\FlappyBird\main.cpp:2:
E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/streambuf:810:7: error: 'std::basic_streambuf<_CharT, _Traits>& std::basic_streambuf<_CharT, _Traits>::operator=(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits]' is private
       operator=(const basic_streambuf&) { return *this; };
       ^
In file included from C:\Users\bader\Desktop\FlappyBird\main.cpp:2:0:
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:341:10: error: within this context
   struct sEntry : public std::streambuf {
          ^
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h: In member function 'olc::rcode olc::ResourcePack::LoadPack(std::string)':
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:1050:24: error: use of deleted function 'olc::ResourcePack::sEntry& olc::ResourcePack::sEntry::operator=(const olc::ResourcePack::sEntry&)'
    mapFiles[sFileName] = e;
                        ^
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h: In member function 'olc::ResourcePack::sEntry olc::ResourcePack::GetStreamBuffer(std::string)':
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:1068:24: error: use of deleted function 'olc::ResourcePack::sEntry::sEntry(const olc::ResourcePack::sEntry&)'
   return mapFiles[sFile];
                        ^
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:341:10: note: 'olc::ResourcePack::sEntry::sEntry(const olc::ResourcePack::sEntry&)' is implicitly deleted because the default definition would be ill-formed:
   struct sEntry : public std::streambuf {
          ^
In file included from E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/ios:43:0,
                 from E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/ostream:38,
                 from E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/iostream:39,
                 from C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:224,
                 from C:\Users\bader\Desktop\FlappyBird\main.cpp:2:
E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/streambuf:802:7: error: 'std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits]' is private
       basic_streambuf(const basic_streambuf& __sb)
       ^
In file included from C:\Users\bader\Desktop\FlappyBird\main.cpp:2:0:
C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:341:10: error: within this context
   struct sEntry : public std::streambuf {
          ^
In file included from C:\Users\bader\Desktop\FlappyBird\main.cpp:4:0:
C:\Users\bader\Desktop\FlappyBird\olcPGEX_Sound.h: In member function 'olc::rcode olc::SOUND::AudioSample::LoadFromFile(std::string, olc::ResourcePack*)':
C:\Users\bader\Desktop\FlappyBird\olcPGEX_Sound.h:297:68: error: use of deleted function 'olc::ResourcePack::sEntry::sEntry(olc::ResourcePack::sEntry&&)'
    olc::ResourcePack::sEntry entry = pack->GetStreamBuffer(sWavFile);
                                                                    ^
C:\Users\bader\Desktop\FlappyBird\olcPGEX_Sound.h: At global scope:
C:\Users\bader\Desktop\FlappyBird\olcPGEX_Sound.h:583:50: error: use of deleted function 'std::atomic::atomic(const std::atomic&)'
  std::atomic SOUND::m_nBlockFree = 0;
                                                  ^
In file included from C:\Users\bader\Desktop\FlappyBird\olcPixelGameEngine.h:230:0,
                 from C:\Users\bader\Desktop\FlappyBird\main.cpp:2:
E:/Programs/DevC++/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/atomic:624:7: note: declared here
       atomic(const atomic&) = delete;
       ^
CMakeFiles\FlappyBird.dir\build.make:61: recipe for target 'CMakeFiles/FlappyBird.dir/main.cpp.obj' failed
mingw32-make.exe[3]: *** [CMakeFiles/FlappyBird.dir/main.cpp.obj] Error 1
CMakeFiles\Makefile2:74: recipe for target 'CMakeFiles/FlappyBird.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/FlappyBird.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/FlappyBird.dir/rule] Error 2
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/FlappyBird.dir/rule' failed
Makefile:117: recipe for target 'FlappyBird' failed
mingw32-make.exe: *** [FlappyBird] Error 2

strstream is deprecated

strstream is deprecated in favor of stringstream. GCC screams it's head off, but compiles anyway, so it's more a qol enhancement, but strstream can technically be removed at any time due to it's deprecation.

in olcPGEX_Graphics3D.h

on line 74:
#include <strstream>
should change to
#include <sstream>

on line 877:
std::strstream s;
should change to
std::stringstream s;

I get this error mental error

mental::filesystem::v1::__cxx11::path const&)'

/tmp/ccxmcPpG.o: In function `std::experimental::filesystem::v1::__cxx11::path::path<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::experimental::filesystem::v1::__cxx11::path>(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)':

olcExampleProgram.cpp:(.text.ZNSt12experimental10filesystem2v17__cxx114pathC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES3_EERKT[ZNSt12experimental10filesystem2v17__cxx114pathC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES3_EERKT]+0x70): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'

/tmp/ccxmcPpG.o: In function `std::thread::thread<void (olc::PixelGameEngine::)(), olc::PixelGameEngine>(void (olc::PixelGameEngine::&&)(), olc::PixelGameEngine&&)':

olcExampleProgram.cpp:(.text.ZNSt6threadC2IMN3olc15PixelGameEngineEFvvEJPS2_EEEOT_DpOT0[ZNSt6threadC5IMN3olc15PixelGameEngineEFvvEJPS2_EEEOT_DpOT0]+0x33): undefined reference to `pthread_create'

collect2: error: ld returned 1 exit status

Incorrect rendering using OpenGL

On my machine the OpenGL viewport does not work properly. It might be a bug in my very old version of Windows (2015 LTSB or Version 10.0.10240)

image

As you can see the top part of the viewport is rendered under the title bar.
I suspect the problem is caused by the dwm. It feels like OpenGL is rendering correctly but then the resulting viewport (that fits the client area) is stretched so it fills the entire window including the window borders. Very strange.

The only way I have found to get the olcPixelGameEngine to work properly on my machine is to not use OpenGL. DirectX works perfectly.

This is the result of running the same code with DirectX:

image

(I have added the red border and the diagonal line to debug this issue)

Idea: Can we add a curated list of PGE Showcase projects into the Repo

There are many users out there who enjoy coding stuff using the PGE.

How about creating a curated list of PGE projects that various users have created, links to GitHub repo's, or links to YouTube or other videos?

I can understand that this might be a bit dangerous, to moderate and to keep things secure/safe for the public. But still, I think this can be considered by @OneLoneCoder as a reach-out for those of us who do not have many options to enlist their creations.

olc::vi2d multiplication with double is not commutative

In this example:

olc::vi2d a{100,100};
olc::vi2d b = a * 0.7;
olc::vi2d c = 0.7 * a;

b will not equal c.


This is because the two operators are not doing the same mathematical operation:

inline v2d_generic operator * (const T& rhs) const { return v2d_generic(this->x * rhs, this->y * rhs); }
This one takes the argument of the same type as the template argument, for olc::vi2d that is an int, hence it will first cast the 0.7 (double) to 0 (int), then multiply.

template<class T> inline v2d_generic<T> operator * (const double& lhs, const v2d_generic<T>& rhs){ return v2d_generic<T>(lhs * rhs.x, lhs * rhs.y); }
This one on the other hand, takes the argument specifically as a double and multiplies the double with the template type and then casts to the template type.

These two operators offer a different functionality than is expected.

why doesnt there exist only one version which takes a different template argument type for the scalar, and one operator for the "lhs * vector" order which swaps the two arguments and calls the other operator?

Suggestion: saving to .png files.

I had to use external library for saving images. would be super nice to have the ability of saving to .png straight from olcPixelGameEngine!

macOS (10.15) loading sprite

When attempting to load a png from my OnUserCreate() I get:
2019-10-18 17:36:41.202483+0200 olcTest[7766:431005] [olcTest] CGContextSetCompositeOperation: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

Any ideas on where to look ? I am building from within xcode using the xcode application template provided.

Run on VS Code

I tried to run the example program in VS Code and it is giving me multiple errors. First, it gave the error: <experimental/filesystem> no such file exists. I then tried commenting this part out and just leaving it as and then the error subsided.

But then a new error popped:
olcPixelGameEngine.h:1235:8:
std::thread t = std::thread(&PixelGameEngine::EngineThread, this);
^~~~~~
olcPixelGameEngine.h:1248:3: error: 't' was not declared in this scope
t.join();

Compiling with g++

Using Pixel Game Engine v1.23 (no problem with v1.20) source compiles, but attempting to run main.exe produces error message:

The procedure entry point _ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEC1Ev
could not be located in the dynamic link library.

g++ main.cpp -o main -luser32 -lgdi32 -lopengl32 -lgdiplus -lShlwapi -lstdc++fs

Version: g++ (Rev2, Built by MSYS2 project) 9.2.0

VS Code Version: 1.42.1 (user setup)
Using C/C++ extention and Code Runner.

OS: Windows_NT x64 10.0.18362

No such problem using Visual Studio.

The library order is important in g++. Could this be causing the problem?

EDIT:
Setting the compiler options: -std=c++17 produces:

error: 'namespace _gfs = std::std::filesystem;' conflicts with a previous declaration

note: previous declaration 'namespace _gfs = std::experimental::filesystem::std::experimental::filesystem::v1;'

Possible problem with drawing drawing 3D obj files

If you use teapot.obj from the Videos repository with olcPixelGameEngine.h and OneLoneCoder_PGE_olcEngine3d.cpp, things are generally working (which is very cool) but there do seem to be issues. For example, the knob at the top of the lid is visible through the sides of the teapot as is the spout and the handles. On the other hand, the bottom of the teapot behaves as expected and blocks the view of those parts of the teapot when they are behind it. I am running this on Arch Linux with no changes to olcPixelGameEngine.h and none to the olcEngine3d.cpp (other than bypassing the texture code for these tests). First of all, I was wondering if someone can confirm that they are seeing the same thing as I assume what I am seeing is not the desired behavior. Thanks.

olcPixelGameEngine.h:1031:24: error: ‘_gfs’ has not been declared

Hi, I'm quite a beginner, but maybe it's worth to mention that I have this issue:

$ g++-9 -g -Wall -o test olcExampleProgram.cpp -std=c++17 -lX11 -lGL -lpthread -lpng -lstdc++fs
In file included from olcExampleProgram.cpp:2:
olcPixelGameEngine.h: In member function ‘bool olc::ResourcePack::AddFile(const string&)’:
olcPixelGameEngine.h:1028:7: error: ‘_gfs’ has not been declared
1028 | if (_gfs::exists(file))
| ^~~~
olcPixelGameEngine.h:1031:24: error: ‘_gfs’ has not been declared
1031 | e.nSize = (uint32_t)_gfs::file_size(file);

Actually, a question. Because I don't use Discord. About the RNG Universe.

Where did you get your Lehmer PRNG? It doesn't look like anything on the Wikipedia page you showed. It looks more sophisticated, with extra hardening of the results.

PS, when are you going to upload the NES part 6 code? Did you get a cease-and-desist from Nintendo? I was just taking the piss out of you about actually using git. Please don't tell me you tried and are now in a detached head state that you don't know how to reattach.

Pressing left or right shift sets other key codes true

in the OnUserUpdate method I have a simple if statement

if (GetKey(olc::Key::A).bHeld)
doSomething();

when I press either of the shifts on my keyboard it sets it to true. this should only
be true when 'A' is being held.

Memory leaks for olc::Sprite

Hi,
firstly I wanted to thank you for your code.
I was using the main thing (OlcPixelEngine) and encountered some memory leaks with valgrind, I think the issue is in this line:
669 if (pColData) delete pColData;
I think changing it to
669 if (pColData) delete[] pColData;
would fix it.

Additionally, there are some other memory leaks in Sprite::LoadFromFile(), mainly in lines:
768 png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
771 info = png_create_info_struct(png);
805 row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * height);

After some time, I found that adding
for (int y = 0; y < height; y++)
free(row_pointers[y]);
free (row_pointers);
png_destroy_read_struct(&png, &info, png_infopp_NULL);
at the ned of the LoadFromFIle() function fixes the final three leaks.

Regards,
Maks

Compiling on OSX

I did this to compile on OSX and it worked perfectly. OSX 10.14.6 (18G95)

/usr/local/bin/g++-9 -o olcExample olcExampleProgram.cpp -L/opt/X11/lib -lX11 -lGL -lpthread -lpng -framework OpenGL -I/opt/X11/include

g++ was installed through brew (clang fails)

I didn't submit a pull on documentation, didn't want to assume how you wanted it.

I've got 175 errors on VS 2019 Community and I can't get it to work

There are so many errors that AI don't know how to make more progress.... Any help, please? The olcConsoleGameEngine was pretty simple to use, but this one is just pain in the neck.

SeverityCodeDescriptionProjectFileLineSuppression State
Error (active)E0035#error directive: The <experimental/filesystem> header providing std::experimental::filesystem is deprecated by Microsoft and will be REMOVED. It is superseded by the C++17 header providing std::filesystem. You can define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING to acknowledge that you have received this warning.PixelGameEngineC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\experimental\filesystem28
Error (active)E0260explicit type is missing ('int' assumed)PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h446
Error (active)E0135namespace "olc" has no member "rcodeConstruct"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h446
Error (active)E0260explicit type is missing ('int' assumed)PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h447
Error (active)E0135namespace "olc" has no member "rcodeStart"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h447
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h545
Error (active)E0135class "olc::Pixel" has no member "ModenPixelMode"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h545
Error (active)E0321data member initializer is not allowedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h545
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h546
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h547
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h548
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h549
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h550
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h551
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h552
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h553
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h554
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h555
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h556
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h557
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h558
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h559
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h560
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h561
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h562
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h563
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h564
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h565
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h566
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h567
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h568
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h569
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h570
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h571
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h572
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h577
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h578
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h579
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h581
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h582
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h583
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h586
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h587
Error (active)E0077this declaration has no storage class or type specifierPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h594
Error (active)E0260explicit type is missing ('int' assumed)PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h596
Error (active)E0135class "olc::PixelGameEngine" has no member "Construct"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1164
Error (active)E0020identifier "nScreenWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1166
Error (active)E0020identifier "nScreenHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1167
Error (active)E0020identifier "nPixelWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1168
Error (active)E0020identifier "nPixelHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1169
Error (active)E0020identifier "bFullScreen" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1170
Error (active)E0020identifier "bEnableVSYNC" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1171
Error (active)E0020identifier "fPixelX" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1173
Error (active)E0020identifier "fPixelY" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1174
Error (active)E0020identifier "wsAppName" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1180
Error (active)E0020identifier "sAppName" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1180
Error (active)E0020identifier "olc_ConstructFontSheet" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1183
Error (active)E0020identifier "pDefaultDrawTarget" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1186
Error (active)E0020identifier "SetDrawTarget" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1187
Error (active)E0020identifier "nScreenWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1195
Error (active)E0020identifier "nScreenHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1196
Error (active)E0020identifier "glDeviceContext" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1202
Error (active)E0135class "olc::PixelGameEngine" has no member "Start"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1213
Error (active)E0020identifier "olc_WindowCreate" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1216
Error (active)E0020identifier "bAtomActive" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1220
Error (active)E0289no instance of constructor "std::thread::thread" matches the argument listPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1221
Error (active)E0135class "olc::PixelGameEngine" has no member "EngineThread"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1221
Error (active)E0258'this' may only be used inside a nonstatic member functionPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1221
Error (active)E0020identifier "bHasInputFocus" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1269
Error (active)E0020identifier "pKeyboardState" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1274
Error (active)E0020identifier "pMouseState" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1279
Error (active)E0020identifier "nMousePosX" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1284
Error (active)E0020identifier "nMousePosY" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1289
Error (active)E0020identifier "nMouseWheelDelta" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1294
Error (active)E0020identifier "nScreenWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1299
Error (active)E0020identifier "nScreenHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1304
Error (active)E0020identifier "nPixelMode" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1317
Error (active)E0020identifier "fBlendFactor" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1331
Error (active)E0020identifier "fSubPixelOffsetX" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1349
Error (active)E0020identifier "fPixelX" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1349
Error (active)E0020identifier "fSubPixelOffsetY" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1350
Error (active)E0020identifier "fPixelY" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1350
Error (active)E0020identifier "nPixelMode" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1770
Error (active)E0020identifier "elseSetPixelMode" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1772
Error (active)E0020identifier "nPixelMode" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1808
Error (active)E0020identifier "nPixelMode" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1813
Error (active)E0020identifier "nPixelMode" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1819
Error (active)E0020identifier "fBlendFactor" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1824
Error (active)E0020identifier "nScreenWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1848
Error (active)E0020identifier "nPixelWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1848
Error (active)E0020identifier "nScreenHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1849
Error (active)E0020identifier "nPixelHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1849
Error (active)E0020identifier "nViewW" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1852
Error (active)E0020identifier "nWindowWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1852
Error (active)E0020identifier "nViewH" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1853
Error (active)E0020identifier "nWindowHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1855
Error (active)E0020identifier "nViewX" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1861
Error (active)E0020identifier "nViewY" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1862
Error (active)E0020identifier "nWindowWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1867
Error (active)E0020identifier "nWindowHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1868
Error (active)E0020identifier "nMouseWheelDeltaCache" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1874
Error (active)E0020identifier "nViewX" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1883
Error (active)E0020identifier "nViewY" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1884
Error (active)E0020identifier "nMousePosXcache" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1886
Error (active)E0020identifier "nWindowWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1886
Error (active)E0020identifier "nScreenWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1886
Error (active)E0020identifier "nMousePosYcache" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1887
Error (active)E0020identifier "nWindowHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1887
Error (active)E0020identifier "nScreenHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1887
Error (active)E0135class "olc::PixelGameEngine" has no member "EngineThread"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1900
Error (active)E0020identifier "olc_OpenGLCreate" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1903
Error (active)E0020identifier "glBuffer" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1907
Error (active)E0020identifier "nScreenWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1912
Error (active)E0020identifier "nScreenHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1912
Error (active)E0020identifier "pDefaultDrawTarget" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1912
Error (active)E0020identifier "OnUserCreate" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1915
Error (active)E0020identifier "bAtomActive" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1916
Error (active)E0020identifier "bAtomActive" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h1921
Error (active)E0020identifier "pKeyboardState" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2017
Error (active)E0020identifier "pKeyNewState" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2020
Error (active)E0020identifier "pKeyOldState" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2020
Error (active)E0020identifier "pMouseState" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2040
Error (active)E0020identifier "pMouseNewState" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2043
Error (active)E0020identifier "pMouseOldState" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2043
Error (active)E0020identifier "nMousePosX" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2062
Error (active)E0020identifier "nMousePosXcache" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2062
Error (active)E0020identifier "nMousePosY" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2063
Error (active)E0020identifier "nMousePosYcache" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2063
Error (active)E0020identifier "nMouseWheelDelta" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2065
Error (active)E0020identifier "nMouseWheelDeltaCache" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2065
Error (active)E0020identifier "OnUserUpdate" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2073
Error (active)E0020identifier "nViewX" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2077
Error (active)E0020identifier "nViewY" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2077
Error (active)E0020identifier "nViewW" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2077
Error (active)E0020identifier "nViewH" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2077
Error (active)E0020identifier "fSubPixelOffsetX" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2085
Error (active)E0020identifier "fSubPixelOffsetY" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2085
Error (active)E0020identifier "glDeviceContext" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2093
Error (active)E0020identifier "fFrameTimer" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2101
Error (active)E0020identifier "nFrameCount" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2102
Error (active)E0020identifier "sAppName" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2107
Error (active)E0020identifier "olc_hWnd" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2110
Error (active)E0020identifier "OnUserDestroy" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2124
Error (active)E0020identifier "glRenderContext" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2136
Error (active)E0020identifier "olc_hWnd" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2137
Error (active)E0020identifier "ULONG_PTRtoken" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2158
Error (active)E0020identifier "token" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2159
Error (active)E0020identifier "nWindowWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2225
Error (active)E0020identifier "nScreenWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2225
Error (active)E0020identifier "nPixelWidth" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2225
Error (active)E0020identifier "nWindowHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2226
Error (active)E0020identifier "nScreenHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2226
Error (active)E0020identifier "nPixelHeight" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2226
Error (active)E0020identifier "nViewW" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2233
Error (active)E0020identifier "nViewH" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2234
Error (active)E0020identifier "bFullScreen" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2237
Error (active)E0020identifier "glDeviceContext" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2302
Error (active)E0020identifier "glRenderContext" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2315
Error (active)E0020identifier "nViewX" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2318
Error (active)E0020identifier "nViewY" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2318
Error (active)E0020identifier "nViewW" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2318
Error (active)E0020identifier "nViewH" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2318
Error (active)E0020identifier "bEnableVSYNC" is undefinedPixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2322
Error (active)E0135class "olc::PixelGameEngine" has no member "bHasMouseFocus"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2352
Error (active)E0135class "olc::PixelGameEngine" has no member "bHasInputFocus"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2353
Error (active)E0135class "olc::PixelGameEngine" has no member "bHasInputFocus"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2354
Error (active)E0135class "olc::PixelGameEngine" has no member "pKeyNewState"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2355
Error (active)E0135class "olc::PixelGameEngine" has no member "pKeyNewState"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2356
Error (active)E0135class "olc::PixelGameEngine" has no member "pMouseNewState"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2357
Error (active)E0135class "olc::PixelGameEngine" has no member "pMouseNewState"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2358
Error (active)E0135class "olc::PixelGameEngine" has no member "pMouseNewState"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2359
Error (active)E0135class "olc::PixelGameEngine" has no member "pMouseNewState"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2360
Error (active)E0135class "olc::PixelGameEngine" has no member "pMouseNewState"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2361
Error (active)E0135class "olc::PixelGameEngine" has no member "pMouseNewState"PixelGameEngineC:\Users\matja\source\repos\PixelGameEngine\olcPixelGameEngine.h2362
ErrorC1189#error: The <experimental/filesystem> header providing std::experimental::filesystem is deprecated by Microsoft and will be REMOVED. It is superseded by the C++17 header providing std::filesystem. You can define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING to acknowledge that you have received this warning.PixelGameEngineC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\experimental\filesystem30

UTF16-LE encoded source file (intepreted as "binary")

The file in question is recently added OneLoneCoder_PGE_olcEngine3D.cpp.
I think you accidentally saved it with UTF16-LE encoding, as all other files seems to be in UTF8. This single file is being interpreted as binary file on GitHub (if you try to open it... even in commit it came with it is being shown that way).

Filling a sprite with 0 alpha Pixels leads to them being black

if i have a newly created sprite, with the pixelmode set to SetPixelMode(olc::Pixel::Mode::ALPHA); it evaluates the alpha blend of the existing empty pixels and the inserted one to black.
the default construcor of Pixel with which the Sprite has been filled (0,0,0,255) and any Pixel value of (r,g,b,0)
will result in a black tone of (0,0,0,255).
this confused me as i expected to create an empty sprite which i then fill with an empty/transparent color. then i could add little things in the sprite which would float.
but they would actually be atop of black.

to fix this i can set the SetPixelMode(olc::Pixel::Mode::NORMAL); and then fill the sprite with transparent Pixels, then reset the SetPixelMode(olc::Pixel::Mode::ALPHA); and insert my "floating" pieces.

Question about guidance and advice

Hi OneLoneCoder, I have been following you for a while now and watching your videos on youtube is a delight and also an inspiration. I am a beginning programmer and I am currently learning CPP on my own. I had a few questions that if you could answer would really help me in my coding journey:

  • First, In every c++ tutorial I find, they teach the basics of C++ and then move data structures or projects where they use pre-made header files for almost everything. I want to learn how to make those header files from basic as you did in your PixelGameEngine and ConsoleGameEngine.

  • Secondly, I am currently working on making a 2D/3D graphing calculator in c++ but I am having trouble finding resources that help teach how to do this.

It would be a real help if you could refer me to some resources that deal with these things and also offer me some advice on how to make projects like you did.

Thank you for taking the time to read my request!

CygWin64 (NetBeans) on Win10 fails to compile the Header

I have CygWin64 on Netbeans, on a Win10 PC.

I've tried an hour to solve each problem that I faced on the way. Sharing it to help other Cygwin / Netbeans folks.

Here's what worked:

  1. replace _Win32_ --> __CYGWIN__ (EVERYWHERE inside the Header file!!!)
  2. add Compiler option: -std=c++11
  3. replace sprintf_s --> sprintf
    so that it reads:
    sprintf(sTitle, "OneLoneCoder.com - Pixel Game Engine - %s - FPS: %d", sAppName.c_str(), nFrameCount);
  4. #include <locale>

and here's where I'm out of solutions:

error:

/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:669:(.text+0xae3): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `GdiplusStartup'

I tried adding the compiler option: "-Wl,--image-base -Wl,0x10000000", which I found on the internet. After this step, I still received several errors, as can be seen below.

I hope to be able to run the PixelGameEngine pretty soon! :)

Thanks!


cd 'C:\Projects\pxl'
C:\cygwin64\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Projects/pxl'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/pxl.exe
make[2]: Entering directory '/cygdrive/c/Projects/pxl'
mkdir -p dist/Debug/Cygwin-Windows
g++ -std=c++11 -lgdiplus    -o dist/Debug/Cygwin-Windows/pxl build/Debug/Cygwin-Windows/olcExampleProgram.o 
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `olc::PixelGameEngine::Start()':
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:669: undefined reference to `GdiplusStartup'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:669:(.text+0xae3): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `GdiplusStartup'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `olc::PixelGameEngine::EngineThread()':
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1165: undefined reference to `__imp_glEnable'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1165:(.text+0x2102): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glEnable'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1166: undefined reference to `__imp_glGenTextures'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1166:(.text+0x2120): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glGenTextures'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1167: undefined reference to `__imp_glBindTexture'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1167:(.text+0x213d): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glBindTexture'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1168: undefined reference to `__imp_glTexParameteri'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1168:(.text+0x2156): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glTexParameteri'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1169: undefined reference to `__imp_glTexParameteri'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1169:(.text+0x216f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glTexParameteri'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1170: undefined reference to `__imp_glTexEnvf'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1170:(.text+0x218a): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glTexEnvf'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1172: undefined reference to `__imp_glTexImage2D'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1172:(.text+0x21f3): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glTexImage2D'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1300: undefined reference to `__imp_glTexSubImage2D'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1300:(.text+0x26be): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glTexSubImage2D'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1303: undefined reference to `__imp_glBegin'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1303:(.text+0x26cc): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glBegin'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1304: undefined reference to `__imp_glTexCoord2f'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1304:(.text+0x26e1): additional relocation overflows omitted from the output
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1304: undefined reference to `__imp_glVertex3f'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1305: undefined reference to `__imp_glTexCoord2f'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1305: undefined reference to `__imp_glVertex3f'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1306: undefined reference to `__imp_glTexCoord2f'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1306: undefined reference to `__imp_glVertex3f'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1307: undefined reference to `__imp_glTexCoord2f'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1307: undefined reference to `__imp_glVertex3f'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1308: undefined reference to `__imp_glEnd'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1312: undefined reference to `__imp_SwapBuffers'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1362: undefined reference to `__imp_wglDeleteContext'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `olc::PixelGameEngine::olc_OpenGLCreate()':
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1492: undefined reference to `__imp_ChoosePixelFormat'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1493: undefined reference to `__imp_SetPixelFormat'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1495: undefined reference to `__imp_wglCreateContext'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1496: undefined reference to `__imp_wglMakeCurrent'
/cygdrive/c/Projects/pxl/olcPixelGameEngine.h:1499: undefined reference to `__imp_wglGetProcAddress'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `Gdiplus::GdiplusBase::operator new(unsigned long)':
/usr/include/w32api/gdiplus/gdiplusbase.h:38: undefined reference to `GdipAlloc'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `Gdiplus::GdiplusBase::operator delete(void*)':
/usr/include/w32api/gdiplus/gdiplusbase.h:46: undefined reference to `GdipFree'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `Gdiplus::Image::~Image()':
/usr/include/w32api/gdiplus/gdiplusheaders.h:70: undefined reference to `GdipDisposeImage'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `Gdiplus::Image::~Image()':
/usr/include/w32api/gdiplus/gdiplusheaders.h:70: undefined reference to `GdipDisposeImage'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `Gdiplus::Image::Clone() const':
/usr/include/w32api/gdiplus/gdiplusheaders.h:75: undefined reference to `GdipCloneImage'
/usr/include/w32api/gdiplus/gdiplusheaders.h:80: undefined reference to `GdipDisposeImage'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `Gdiplus::Bitmap::Clone() const':
/usr/include/w32api/gdiplus/gdiplusheaders.h:194: undefined reference to `GdipCloneImage'
/usr/include/w32api/gdiplus/gdiplusheaders.h:199: undefined reference to `GdipDisposeImage'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `Gdiplus::Image::GetHeight()':
/usr/include/w32api/gdiplus/gdiplusimpl.h:153: undefined reference to `GdipGetImageHeight'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `Gdiplus::Image::GetWidth()':
/usr/include/w32api/gdiplus/gdiplusimpl.h:278: undefined reference to `GdipGetImageWidth'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `Gdiplus::Bitmap::Bitmap(wchar_t const*, int)':
/usr/include/w32api/gdiplus/gdiplusimpl.h:429: undefined reference to `GdipCreateBitmapFromFileICM'
/usr/include/w32api/gdiplus/gdiplusimpl.h:432: undefined reference to `GdipCreateBitmapFromFile'
build/Debug/Cygwin-Windows/olcExampleProgram.o: In function `Gdiplus::Bitmap::GetPixel(int, int, Gdiplus::Color*) const':
/usr/include/w32api/gdiplus/gdiplusimpl.h:603: undefined reference to `GdipBitmapGetPixel'
collect2: error: ld returned 1 exit status
make[2]: *** [nbproject/Makefile-Debug.mk:63: dist/Debug/Cygwin-Windows/pxl.exe] Error 1
make[2]: Leaving directory '/cygdrive/c/Projects/pxl'
make[1]: *** [nbproject/Makefile-Debug.mk:59: .build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Projects/pxl'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2

BUİLD FAILED (exit value 2, total time: 1s)

Sprite has no copy-constructor

I created a custom class which has a sprite as a member and is able to draw itself, a Tile.

I then created temporary copies of my tiles and put them in vectors, these temporaries get deleted, and their copy (implicitly a copy of all its members like position, and the sprite, is created).
then the scope of the temporary ran out and it got deleted along with its sprite.

Now i wanted to use the copy of my tile and draw the sprite, but alas the pColData doesn't point to anything valid any more, as it got deleted by the destruction of the temporary Tile object.

After i found out, i wrote a simple copy constructor for sprites and it works fine.

see my code for more details.

Set custom mouse arrow

Hello,
not really a PixelEngine related problem, but i tried to set a custom cursor arrow in this function:

LRESULT CALLBACK PixelGameEngine::olc_WindowEvent(HWND hWnd, UINT [...]) {
case WM_SETCURSOR: SetCursor(hCurs1);return 0; //created a custom cursor with CreateCursor()
}

which works quite well, it shows my custom cursor arrow, but the cursor disappears after 30 seconds and stays invisible, mouse functions like dragging still work though.

Improving performance of keyboard handling

Hello.
Used PGE a lot, and tried to improve its performances in all possible ways while respecting the high readability of the framework.
To check keyboard events, the framework uses a 256 array to hold the status of each key.
When the event handles (at least on Windows) is executed, another array is altered, and then, on the main cycle, all the 256 items of the keyboard array are updated based on the other array.

I did an optimization in the structure that get rid of the 256 cycle in the main loop.

The code attached is not 100% compatible with PGE but it is quite close.

PGE keyboard improvement.txt

Filling a circle with alpha blending will create visible stripes

the problem seems to stem from the fact that in the FillCircle method the individual lines sometimes get draw multiple times:
grafik

here is my modified example code to generate the above image:

#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
		olc::PixelGameEngine::SetPixelMode(olc::Pixel::ALPHA);
		this->Clear(olc::BLACK);
		FillCircle(100, 100, 60, olc::Pixel(255,0,0,200));
		return true;
	}

	bool OnUserUpdate(float fElapsedTime) override
	{
		// called once per frame
		return true;
	}
};


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

	return 0;
}

and here the modified FillCircle to show that is has overdrawn:

	void PixelGameEngine::FillCircle(int32_t x, int32_t y, int32_t radius, Pixel p)
	{
		// Taken from wikipedia
		int x0 = 0;
		int y0 = radius;
		int d = 3 - 2 * radius;
		if (!radius) return;

		static std::vector<std::vector<int>> hits(260, std::vector<int>(260,0));
		auto drawline = [&](int sx, int ex, int ny)
		{
			for (int i = sx; i <= ex; i++)
			{
				hits[i][ny]++;
				Draw(i, ny, p);
			}
		};

		while (y0 >= x0)
		{
			// Modified to draw scan-lines instead of edges
			drawline(x - x0, x + x0, y - y0);
			drawline(x - y0, x + y0, y - x0);
			drawline(x - x0, x + x0, y + y0);
			drawline(x - y0, x + y0, y + x0);
			if (d < 0) d += 4 * x0++ + 6;
			else d += 4 * (x0++ - y0--) + 10;
		}

		for(auto v : hits)
		{
			for(int i : v)
				std::cout << i;
			std::cout << std::endl;
		}
	}

on the console (background in the image) one can clearly see multiple calls to draw for the same position, because alphablending is enabled this leads to brighter reds than at other positions, hence the stripes.

Compile on Linux

Is there a simple way to compile the 'CarCrimeCity' example in a Linux system?

.PNG Files

I am trying to draw a chess board in olcPixelGameEngine.
I have the pieces images files, saved in .png format.
all works fine but i have problems with the alpha color from the images. The PixelEngine draw all colors and the alpha color too.

Mouse location is not reported correctly on resized windows in X11

Mouse location is not reported correctly on resized windows in X11. This can be fixed with replacing line 1689:
olc_UpdateMouse(xev.xmotion.x, xev.xmotion.y);
with:

XWindowAttributes gwa;
XGetWindowAttributes(olc_Display, xev.xmotion.window, &gwa);
olc_UpdateMouse(
(xev.xmotion.x * nScreenWidth * nPixelWidth) / gwa.width,
(xev.xmotion.y * nScreenHeight * nPixelHeight) / gwa.height);

Faster Sprite Draw Rutines

Some faster Draw Sprite rutines.
Adds 4-8 if checks for ALL sprite tests
Removes w * h if checks for each Draw, SetPixel and GetPixel checks in those Sprite functions if the above checks are meet (The Sprite/partial sprite is within target and source coordinates)

Changed frame rate in application from 40 to 100FPS

////////////////////////////////////////////////////////////
///////// The following functions must be added: ///////////
//////// The declarations must be added /////////
////////////////////////////////////////////////////////////

//Avoids all safty measures for speed
	Pixel GetFastPixel(int32_t x, int32_t y);





	//Avoids all safty measures for speed
	bool  SetFastPixel(int32_t x, int32_t y, Pixel p);






	// Draws a single Pixel without safty measures
	virtual bool DrawFast(int32_t x, int32_t y, Pixel p = olc::WHITE);





Pixel Sprite::GetFastPixel(int32_t x, int32_t y)
{
	if (modeSample == olc::Sprite::Mode::NORMAL) return pColData[y*width + x];
	else return pColData[abs(y%height)*width + abs(x%width)];
}







bool Sprite::SetFastPixel(int32_t x, int32_t y, Pixel p)
{

#ifdef OLC_DBG_OVERDRAW
nOverdrawCount++;
#endif

	pColData[y*width + x] = p;
	return true;

}

bool PixelGameEngine::DrawFast(int32_t x, int32_t y, Pixel p)
{

	if (!pDrawTarget) return false;


	if (nPixelMode == Pixel::NORMAL)
	{
		return pDrawTarget->SetFastPixel(x, y, p);
	}

	if (nPixelMode == Pixel::MASK)
	{
		if (p.a == 255)
			return pDrawTarget->SetFastPixel(x, y, p);
	}

	if (nPixelMode == Pixel::ALPHA)
	{
		Pixel d = pDrawTarget->GetFastPixel(x, y);
		float a = (float)(p.a / 255.0f) * fBlendFactor;
		float c = 1.0f - a;
		float r = a * (float)p.r + c * (float)d.r;
		float g = a * (float)p.g + c * (float)d.g;
		float b = a * (float)p.b + c * (float)d.b;
		return pDrawTarget->SetFastPixel(x, y, Pixel((uint8_t)r, (uint8_t)g, (uint8_t)b));
	}
	if (nPixelMode == Pixel::CUSTOM)
	{
		return pDrawTarget->SetFastPixel(x, y, funcPixelMode(x, y, p, pDrawTarget->GetFastPixel(x, y)));
	}
	return false;
}

////////////////////////////////////////////////////////////
//////// The following functions must be modified: /////////
//////// The declarations does NOT change /////////
////////////////////////////////////////////////////////////

void PixelGameEngine::DrawSprite(int32_t x, int32_t y, Sprite *sprite, uint32_t scale)
{
	if (sprite == nullptr)
		return;

	//Fast routine if entire sprite is within entire target:
	if (x > 0 && x + sprite->width < pDrawTarget->width && y > 0 && y + sprite->height < pDrawTarget->height) {
		if (scale > 1)
		{
			for (int32_t i = 0; i < sprite->width; i++)
				for (int32_t j = 0; j < sprite->height; j++)
					for (uint32_t is = 0; is < scale; is++)
						for (uint32_t js = 0; js < scale; js++)
							DrawFast(x + (i*scale) + is, y + (j*scale) + js, sprite->GetFastPixel(i, j));
		}
		else
		{
			for (int32_t i = 0; i < sprite->width; i++)
				for (int32_t j = 0; j < sprite->height; j++)
					DrawFast(x + i, y + j, sprite->GetFastPixel(i, j));
		}

	}

	//// NORMAL rotine
	else {
		if (scale > 1)
		{
			for (int32_t i = 0; i < sprite->width; i++)
				for (int32_t j = 0; j < sprite->height; j++)
					for (uint32_t is = 0; is < scale; is++)
						for (uint32_t js = 0; js < scale; js++)
							Draw(x + (i*scale) + is, y + (j*scale) + js, sprite->GetPixel(i, j));
		}
		else
		{
			for (int32_t i = 0; i < sprite->width; i++)
				for (int32_t j = 0; j < sprite->height; j++)
					Draw(x + i, y + j, sprite->GetPixel(i, j));
		}
	}
}






void PixelGameEngine::DrawPartialSprite(int32_t x, int32_t y, Sprite *sprite, int32_t ox, int32_t oy, int32_t w, int32_t h, uint32_t scale)
{
	if (sprite == nullptr)
		return;
	//Fast routine if entire sprite is within entire target && entire partial sprite is within source sprite:
	if (x > 0 && x + w < pDrawTarget->width && y > 0 && y + h < pDrawTarget->height && ox > 0 && oy > 0 && w < sprite->width && h < sprite->height) {
		if (scale > 1)
		{
			for (int32_t i = 0; i < w; i++)
				for (int32_t j = 0; j < h; j++)
					for (uint32_t is = 0; is < scale; is++)
						for (uint32_t js = 0; js < scale; js++)
							DrawFast(x + (i*scale) + is, y + (j*scale) + js, sprite->GetFastPixel(i + ox, j + oy));
		}
		else
		{
			for (int32_t i = 0; i < w; i++)
				for (int32_t j = 0; j < h; j++)
					DrawFast(x + i, y + j, sprite->GetFastPixel(i + ox, j + oy));
		}
	}

	//// NORMAL rotine
	else {
		if (scale > 1)
		{
			for (int32_t i = 0; i < w; i++)
				for (int32_t j = 0; j < h; j++)
					for (uint32_t is = 0; is < scale; is++)
						for (uint32_t js = 0; js < scale; js++)
							Draw(x + (i*scale) + is, y + (j*scale) + js, sprite->GetPixel(i + ox, j + oy));
		}
		else
		{
			for (int32_t i = 0; i < w; i++)
				for (int32_t j = 0; j < h; j++)
					Draw(x + i, y + j, sprite->GetPixel(i + ox, j + oy));
		}
	}
}

Specify max refresh rate/fps

Can there be an option to define the maximum refresh rate?
Doesn't really make sense to have thousands of frames performance wise.

Sound / Music support

Important: This is not an issue regarding the current scope of PGE, rather an improvement.

I'm basically trying to play a background music over my PGE based game. And I have not been able to do that.

So, PlayBackgroundMusic(), and PlaySound() functions could be added to the game engine.
Sounds can be sound FX, similar to Sprites (loaded at the start of the game.)

(PS: I've searched Google, the Discord server and Github for sound related CPP examples, and couldn't find a proper way to do it. WinMM.lib doesn't work in my case (don't know why!))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.