Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux Support #1

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Linux Support #1

wants to merge 11 commits into from

Conversation

DaveAxiom
Copy link

Proper Linux support for project OpenGL! This contribution is intended to be inline with Cherno's programming intent and style.

Premake creates multiple Makefiles as .make files. Each project Makefile needs to be specified for compilation. To compile OpenGL-Examples, run from the command prompt:
make -f OpenGL-Examples.make

@DaveAxiom DaveAxiom requested a review from TheCherno January 16, 2020 06:32
Without this configuration my system defaults to OpenGL 3.0.
@slzatz
Copy link

slzatz commented Feb 16, 2020

Confirming that these changes providing linux support worked on my arch linux system. Very helpful.

@TheCherno
Copy link
Owner

@DaveAxiom thank you for your contribution! I'll check it out and merge it in once I'm happy. What Linux distro did you use?

@DaveAxiom
Copy link
Author

I use a Ubuntu variant distribution. Ubuntu is a Debian based system which many popular distributions are also based on. The directions for installing required libraries is on the Hazel Project Linux PR branch. https://github.com/LovelySanta/Hazel/tree/linux-support-v2#32-linux

@@ -29,7 +29,7 @@ namespace GLCore {
EventCategoryMouseButton = BIT(4)
};

#define EVENT_CLASS_TYPE(type) static EventType GetStaticType() { return EventType::##type; }\
#define EVENT_CLASS_TYPE(type) static EventType GetStaticType() { return EventType::type; }\
virtual EventType GetEventType() const override { return GetStaticType(); }\

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that Yan is using the token-pasting operator (##) to concat EventType:: with whatever is the name pasted as type argument, so I wouldn't remove the operator here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ## operator is proprietary to Microsoft's compiler!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I am not so sure about it tho as I have used it with gcc and clang professionally under various architecture implementations of the compiler standard. Here's an example code that makes use of the ## operator compiled using gcc-7: https://godbolt.org/z/TEGszs

Also, the cppreference preprocessor docs don't seem to say anything about compiler specifics: https://en.cppreference.com/w/cpp/preprocessor/replace

And I have personally compiled the code under clang and gcc on both Linux (gcc and clang) and MacOS (clang) as is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this operator on Godbolt during the summer and found that ## works on the most recent few major versions of GCC. The above is ::## which is different.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sweet, well not cool but ... 😆 I am wondering what could've made this compile fine for me, as far as I remember tho.
I guess there's nothing more that can be done for the above compiler feature support war. I've been misled :(

Added glfwWindowHint() lines to window creation.
@@ -46,6 +46,10 @@ namespace GLCore {
s_GLFWInitialized = true;
}

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
Copy link

@GeorgeWeb GeorgeWeb Oct 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested addition of:

glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

before the OpenGL profile hint line, because we're using 3.3 which for some OS (macOS) may require core context compatibility-mode enabled. This is due to Apple's move on starting to deprecate a bunch of APIs - OpenGL, OpenCL, etc. in favor of Metal.

I am aware that this MR is solely about Linux support, but just wanted to mention a point of consideration about GL context support:

macOS: The OS only supports forward-compatible core profile contexts for OpenGL versions 3.2 and later. Before creating an OpenGL context of version 3.2 or later you must set the GLFW_OPENGL_FORWARD_COMPAT and GLFW_OPENGL_PROFILE hints accordingly. OpenGL 3.0 and 3.1 contexts are not supported at all on macOS.
More on this in the glfw official docs: https://www.glfw.org/docs/3.3/window_guide.html#GLFW_OPENGL_FORWARD_COMPAT_hint

I am only suggesting this because I've done some of the work on my Mac at some point and had to adjust a couple of things.

It is up to you and maybe @TheCherno if he'd like to have a look, but you can use some PLATFORM macro at config time and add this for macOS only, or not do anything but keep in mind for future reference.

Also, from the message of the commit adding the above hints:

Added glfwWindowHint() lines to window creation.
Without this configuration my system defaults to OpenGL 3.0.

wrt macOS but also on API support general:

On macOS you might consider throwing an error message or something or just assert the version for the time being as creating an OpenGL core context below 3.1 is not supported at all. So maybe either disallow < 3.3 if we're not gonna consider API compatibility for these versions or wrap it around a PLATFORM macro too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not well versed on the specifics of OpenGL. I know that there are different OpenGL profiles but I don't know about the specifics of each. I held off on accepting the Hints PR into this branch until now since I rationalized that it is a minimum that can be just a starting point. Cherno plans to make videos on Apple support.

My philosophy behind Linux support is to increase the portability of this project. Apple support is good but the actions of that company are intended to close their platform in order to add proprietary value to their Intellectual Properties. Therefore anyone that buys an Apple shouldn't expect compatibility and I'm not going to dive in further to engineer around Apple. If this PR is accepted, a future PR could be submitted to modify the new base project.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I guess I just threw this out here for informative reasons. What you're saying makes sense. :)

@alboainin
Copy link

alboainin commented Oct 28, 2020

Running the OpenGL-Example one failed to load returning this error

[00:09:29] GLCORE: Could not open file 'assets/shaders/test.vert.glsl'
[00:09:29] GLCORE: Could not open file 'assets/shaders/test.frag.glsl'
[00:09:29] GLCORE: [OpenGL Debug HIGH] 0:1(1): error: syntax error, unexpected $end
[00:09:29] GLCORE: Assertion Failed: GL_DEBUG_SEVERITY_HIGH

Os: Linux Ubuntu 20.4 LTS

@DaveAxiom
Copy link
Author

@AliAlboainin96 This branch is modified minimally to make it easy to merge. Change into the OpenGL-Examples directory and try running OpenGL-Examples again. The Hazel project has the same issue and it's expected that an asset manager will be written someday. Sorry about that.

cd OpenGL-Examples
../bin/Debug-linux-x86_64/OpenGL-Examples/OpenGL-Examples

@alboainin
Copy link

@DaveAxiom For some reason deleting the repo and recloning it worked !

@DominoMarama
Copy link

This seg faulted on example for me and I sort of assumed it might be a conflict with installed glfw. As a learning exercise I decided to follow the commits on this to a clean branch and make my own Linux build more to my taste. I didn't really keep easy merging in mind, renaming and moving subprojects (and updating to latest original sources) but I'm pretty happy with the result, especially as it doesn't segfault anymore.

I diverged a fair bit but it might be worth a quick look at mine for things like the system glfw support and copying of shaders. It's my first time using premake so feel free to point out if I've done anything dumb too, I can't test Windows so it's entirely possible I broke it :)

https://github.com/DominoMarama/OpenGL

@pulsatorius
Copy link

u@c:/OpenGL$ bin/Debug-linux-x86_64/OpenGL-Examples/OpenGL-Examples 
[18:05:00] GLCORE: OpenGL Info:
[18:05:00] GLCORE:   Vendor: NVIDIA Corporation
[18:05:00] GLCORE:   Renderer: NVS 5200M/PCIe/SSE2
[18:05:00] GLCORE:   Version: 3.3.0 NVIDIA 390.143
Segmentation fault (core dumped)
u@c:/OpenGL$

@DaveAxiom
Copy link
Author

@pulsatorius

The minimum version of OpenGL needed is 3.3 which is what you have. You do have an old video card. I can give you tips on how to get this project setup in CodeBlocks for you to step through and debug. This is my output for this program:

[22:55:04] GLCORE:   Vendor: X.Org
[22:55:04] GLCORE:   Renderer: AMD Radeon (TM) RX 460 Graphics (POLARIS11, DRM 3.35.0, 5.4.0-72-generic, LLVM 11.0.0)
[22:55:04] GLCORE:   Version: 4.6 (Compatibility Profile) Mesa 20.2.6```

@pulsatorius
Copy link

I use Eclipse not CodeBlocks normally. In this case I use the CLI, with make -j4 -f OpenGL-Sandbox.make.
The version is set by the program. When I run the code I have created from Cherno's OpenGL Course on YouTube, with

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);

, note the COMPAT instead of CORE, I get

4.6.0 NVIDIA 390.143
Registering test Clear Color
Registering test 2D Texture

So the Nvidia driver can run OpenGL 4.6.0.

@pulsatorius
Copy link

pulsatorius commented May 7, 2021

Shouldn't this conversation be held at https://github.com/DaveAxiom/OpenGL?
I tried to debug and got this.

Thread #1 [OpenGL-Sandbox] 152096 [core: 2] (Suspended : Signal : SIGSEGV:Segmentation fault)	
	0x0	
	GLCore::Utils::EnableGLDebugging() at OpenGLDebug.cpp:42 0x5555555d187e	
	SandboxLayer::OnAttach() at SandboxLayer.cpp:16 0x5555555bf4b3	
	GLCore::LayerStack::PushLayer() at LayerStack.cpp:20 0x5555555c43a1	
	GLCore::Application::PushLayer() at Application.cpp:38 0x5555555bfa4b	
	Sandbox::Sandbox() at SandboxApp.cpp:11 0x55555556d215	
	std::make_unique<Sandbox>() at unique_ptr.h:857 0x555555572a99	
	main() at SandboxApp.cpp:17 0x5555555673d7	

It looks like the call to glDebugMessageCallback() gives the segmentation fault.
According to http://docs.gl/gl4/glDebugMessageCallback it was introduced in OpenGL 4.3.

@pulsatorius
Copy link

pulsatorius commented May 7, 2021

If I change lines 49 in /OpenGL-Core/src/Platform/Windows/WindowsWindow.cpp from

49:		glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);

to

49:		glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);

I get a black window, which I think is the correct behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants