Skip to content

Instantly share code, notes, and snippets.

@sortofsleepy
Last active April 10, 2024 01:13
Show Gist options
  • Save sortofsleepy/17609ed01c7e16bacbb0543b14407575 to your computer and use it in GitHub Desktop.
Save sortofsleepy/17609ed01c7e16bacbb0543b14407575 to your computer and use it in GitHub Desktop.
Web/OpenGL -> Unreal Engine
#include "Containers/UnrealString.h"
// Helper function to cut down on the amount of writing needed to log something. Accepts one argument
#define LOG_ARG( stream , args) UE_LOG(LogTemp, Warning, TEXT(stream),args);
// same as LOG_ARG but accepts 2 arguments
#define LOG_2ARG( stream , arg1, arg2) UE_LOG(LogTemp, Warning, TEXT(stream),arg1,arg2);
// same as LOG_ARG but accepts 3 arguments
#define LOG_3ARG( stream , arg1, arg2,arg3) UE_LOG(LogTemp, Warning, TEXT(stream),arg1,arg2,arg3);
// Just logs some information to the console.
#define LOG_I( stream) UE_LOG(LogTemp, Warning, TEXT(stream));
// Logs error message to console
#define LOG_E( stream) UE_LOG(LogTemp, Error, TEXT(stream));

Some general observations about Unreal. Note that I am dumb and some mistakes / misinformation might be present.

Units

1 "unit" in unreal for setting something is approximately setting that object to 0.01 scale.

For example, for the default 100x100x100 cube, to make it 1x1x1, you set the scale of that to 0.01

I believe things are "technically" in cm, but don't quote me on that.

Projection matrices

If you're coming from the GL side, you've undoubtedly heard of glMatrix. Unreal has a built in function called

FPerspectiveMatrix

It does take different parameters though, (while ignoring the "out" prop in glMatrix)

glMatrix

  mat4.perspective(fov,aspect,near,far)

Unreal

  FPerspectiveMatrix(halfFov,width,height,near,far)

Width and height refer to the viewport width,height. Half fov is just the same fov you'd pass into glMatrix divided by 2.


Plugins

When adding classes to Plugin files, make sure to add the <plugin name>_API qualifier to the class, otherwise the .cpp files won't get built.

class MYPLUGIN_API ApiClass {
...

Texture format byte sizes

thanks to Petr Leontev

The global enum GPixelFormats contains information about the various texture formats including byte size.

Game viewport Texture

(still testing)

You can grab the current viewport's render target via GEngine->GameViewport->Viewport->GetRenderTargetTexture()

Note that you should double check to make sure the GEngine and GEngine->GameViewport are not null before fetching; otherwise you'll hit memory issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment