redorav / hlslpp

Math library using hlsl syntax with SSE/NEON support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

compatiblity with opengl?

alighazi opened this issue · comments

commented

I tried replacing handmademath with this library in my opengl application but it broke.

Hi @alighazi, thanks for your message. I had a look at HandmadeMath to see what it was, it looks like an interesting math library. However from your message I don't understand the connection between it and opengl.

As for the problem you're having, could you be more specific? Saying it broke doesn't really give me any clues with which to help you out. Are you experiencing a bug? Does it not compile?

commented

Hi @redorav thanks for the answer.

you can for example replace handmademath with hlslpp here and try it out
https://github.com/GeertArien/learnopengl-examples/blob/master/src/1-9-camera/3-look.c
my program is kinda similar and for me it didn't render anything. If my implementation is alright (which might not be) then it means it breaks because the math is a bit different between opengl and directx?

Hi @alighazi, I took a quick look at the code but I need something more specific than a file with code.

Off the top of my head there are some differences between OpenGL and DIrectX in the view matrix, the projection matrix, and some math functions such as frac vs fract, etc. HLSL++ makes some assumptions that are common in DirectX, but are configurable. There are also differences in the logical matrix layouts (column vs row), and HLSL++ does have ways of modifying those too.

I would suggest stepping through the code in two Visual Studio instances and watch the variables as they change through your code until you find the discrepancy. If you can point to specific places we can have a more meaningful discussion about it.

commented

ok do you know how view and projection matrix are different vs opengl?
Also how in hlslpp I can switch matrix layout (row <=> column) without having to transpose ?

OpenGL and DirectX have historically favored different handedness regarding view and projection matrices, but also regarding the depth range DirectX is [0, 1] and OpenGL [-1, 1]

Typically you'll want to look at hlsl++_transform_common.h

// Row-Major logical layout (default)
// assumes "vector-row(N) * matrix(NxM)" multiplication order
#define HLSLPP_LOGICAL_LAYOUT_ROW_MAJOR 0

// Column-Major logical layout (optional)
// assumes "matrix(MxN) * vector-column(N)" multiplication order
#define HLSLPP_LOGICAL_LAYOUT_COL_MAJOR 1

// Default HLSL++ logical layout is Row-Major
// It can be changed by overriding this definition value externally
#ifndef HLSLPP_LOGICAL_LAYOUT
	#define HLSLPP_LOGICAL_LAYOUT HLSLPP_LOGICAL_LAYOUT_ROW_MAJOR
#endif
// Left-Handed coordinate system (e.g. DirectX, Metal)
// The positive x, y and z axes point right, up and forward.
// Positive rotation is clockwise about the axis of rotation.
#define HLSLPP_COORDINATES_LEFT_HANDED 0

// Right-Handed coordinate system (e.g. OpenGL, Vulkan)
// The positive x, y and z axes point right, up and backward.
// Positive rotation is counterclockwise about the axis of rotation.
#define HLSLPP_COORDINATES_RIGHT_HANDED 1

and

namespace zclip
{
    enum t
    {
	    zero,     // Clip points with z < 0 in projection coordinates (e.g. DirectX, Vulkan, Metal)
	    minus_one // Clip points with z < -1 in projection coordinates (e.g. OpenGL)
    };
}

Closing due to lack of activity, let me know if this needs reopening