[Episode 5] [Code] Setup SDL2 and OpenGL and first OpenGL function (glGetString) - Modern OpenGL
Вставка
- Опубліковано 27 вер 2024
- ►Full OpenGL Series Playlist: • Introduction to OpenGL
►Find full courses on: courses.mshah.io/
►Join as member to get perks: / @mikeshah
►Lesson Description: In this lesson I show you step by step how to create an SDL2 window, setup an opengl context, and ultimately call your first OpenGL function. This is a longer lesson, but should be useful in helping you put together all the information you need to get started with OpenGL programming.
►Please like and subscribe to help the channel!
►UA-cam Channel: / mikeshah
►Join our free community: courses.mshah.... - Наука та технологія
Exactly what I needed! so professional and to the point. Thanks!
Cheers!
Amazing series, your a life changer! So glad I found it while looking to start actually learning C++ and OpenGL. Got it working on Windows with MSYS2
Cheers, enjoy!
I just started a Bachelor in Automation Engineering where I had an introduction to strict C.
I managed to get this OpenGL and SDL2 because of this lesson and, in my opinion, this channel should be in the 500k views.
Good explanations, lots of fiddling around (which is actually awesome because you get to see some quality troubleshooting).
Love it so far!
Cheers, thanks for the kind words! Channel growing slow and steady 😁
This is Wonderful! I'm enjoying following along in linux using the command line to compile and just a simple text editor to code. Looking forward to the rest of the series!
Cheers thank you for the kind words!
Incredible that this course is free! Thanks a lot Mike
Cheers, thanks for the kind words!
The cool thing about this video is that you made everything from scratch and separated each part of the process. It became easier to understand how OpenGL really works.
Thank you! Follow up videos are going to keep reinforcing these ideas 😁 💡
@@MikeShah I know it's a lot of work to make the videos, but over time people will show up and in time you'll be at the top! Hugs!
@@MarcosCpp Thank you for the support and words of encouragement! 😁
Mike is an AMAZING teacher!! We need him in Russia
Cheers! Thank you for the kind words!
Thanks for your great videos MAN
Cheers, you are most welcome!
There is also the SDL_opengl.h header file that I have seen in other tutorials. I saw it includes the same OpenGL API functions/constants found in GLAD, such as glGetString, GL_VENDOR, etc, although I had some linker issues when I tried to compile that I didn't bother with. Do you happen to know what is SDL_opengl.h used for? From what I see it can be used in place of GLAD/other OpenGL extensions but I don't see it ever used.
I believe SDL_opengl only supports older OpenGL functions, so it's still best to use something like glad, glew, etc. to load the OpenGL extensions.
Great video
Cheers!
Thanks for that awesome video.
Can someone tell me pls, how can I set up my terminal to be so simple and convinient like your one? In which direction I should look?
Cheers! My terminal is just vanilla vim and tmux :)
I just recently started working on getting a GLFW project up and running but for some reason whenever I build and run, the window pops up but Linux wants to force quit the process.
Looking forward to your future videos so I can keep working in OpenGL
Hmm strange that glfw is doing that--perhaps try a stable version of glfw and see if that continues? I wonder if the order of setting things up is mixed up. Otherwise, feel free to follow the SDL2 instructions in this series (and more instructions on my SDL2 series for setting up window with OpenGL).
At some point, I will run through these setups with glfw.
Hi. I have a question. Why did you choose SDL2 for OpenGL and not GLFW for example?
It's a bit more rich of a library and commercially it has been used on many platforms which has some appeal.
If I wanted the openGL window to be a panel or frame within a wxWidgets app, how would these steps you do here be incorporated in the wxWidgets app? I mean, would this code be in some other function or must it be where I setup the frame or panel in my application? Im a little lost as to how to setup openGL in wxWidgets. Thank you.
It's on my todo list for my wxWdigets series (ua-cam.com/play/PLvv0ScY6vfd9QZOUbQ2YMghuxWnFoWuiU.html) to talk about Modern OpenGL with wxglcanvas. The samples otherwise have a few examples you could otherwise modify :)
I want to create a 3D games, should I need combine SDL2 and OpenGL
Correct! This series will help you with that. Other options include using a game engine like Unity3D or Unreal Engine if you do not want to do everything from scratch
and seem glfwPollEvents is better than Pool Event of SDL because the CPU still in low percent when app go to glfwPollEvents
Interesting! I haven't compared both
@@MikeShah yes when apps run too SDL pool event, the CPU going to 100%
can i use glad instead?
We use glad in this video
Everything was going well until I got to the part where you ran the program and your window popped up. When I run the program there are no errors and the main event loop is running (tested it with cout and it just fills my terminal) but no window seems to show up? Any ideas?
Hmm, hard to know without seeing it. I'm guessing SDL2 is not being initialized -- you could try to return the error code and see what that gives you. Specs on your operating system are also useful. Post the fix here or on "courses.mshah.io forums" if you find anything
@@MikeShah that’s the thing that’s so weird, there is no error. I have your code practically copied 1to1 up to the point where you run it with a window popping up on your other sceeen for the first time. I’m running it on Ubuntu on a Surface Book Gen 1 which supports OpenGL 4.6 (but I don’t think the OpenGL support has to do with the window not showing)
When I get a chance I’ll push the file onto GitHub and and comment the link
@@MikeShah this is what I’ve got so far, let me know if you spot anything incorrect! Any and all feedback is greatly appreciated, thank you. github.com/jackphillips31/OpenGL-Mandelbrot/blob/master/main.cpp
Ps the compiled prog on that repo isn’t updated
@@Fr0sTyProductions My guess is you'll need to update the mesa drivers. Try changing the MAJOR and MINOR versions to something like 3 and 3 respectively. I forget the exact command to update mesa on ubuntu, but it'll be something like sudo apt-get update libemesa-dev
I am having some issues with the default GPU to render this. i am not sure how to change it.
context:
- I am using WSL2 Ubuntu 22.04
- I have AMD Radeon 780m Graphics integrated gpu
- and NVIDIA GeForce rtx 4060 laptop gpu
when i do lspci it shows both of them as "Microsoft Corporation Device 008e"
and for the line > std::cout
nevermind i figure it out, i just needed to update the environment variable like so
$ export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA
thanks for the awesome tutorials mike, i completed the C++ series (well 70%) and started this now. really enjoying it. :D
@@marshedmello Cheers! And thanks for also sharing the solution with the community!
I love your videos. After learning sdl, i was bored so I followed your tutorials to learn OpenGL. So far, I have been learning a lot
@@JumpercraftYT cheers, happy to hear that!
Hi Michael, thanks for the videos in this series! Why not having a Github repository?
Cheers! 1.) More to maintain 2.) Avoid students copying & pasting
Only your tutorials worked out for me, they are one of their kind.
This is not a problem, but: When you executed your application after all changes( addition of glGetString(GL_RENDERER) ), it showed in "out": nvidia discrete gpu, but for me it shows intel integrated with "mesa"
I tried to grep glxinfo and it showed my nvidia discrete card
Is there a way to set a default renderer to GPU in my current source code?
(sorry, I tried to google it, but I couldn't find any suitable answers)
Cheers! Thanks for the kind words. Usually can select gpu from operating system or perhaps device settings
I managed to find solution, but I think it's nearly impossible to use Nvidia gpus on linux. I'm using Fedora 37 and I only solved problem with downgrading drivers and setting up Machine Owner Keys for Nvidia drivers.
Is it worth spending time on linux to learn graphics/gamedev programming?
Or It's better to stick with windows DirectX ( don't know about Vulkan) ?
@@heyheyheyhoev419 Still worth it to do OpenGL on linux in my opinion. Historically nVidia was more difficult on linux, but I believe that to be improved or improving over time. DirectX is also coming to WSL -- so that is a big bonus for development! devblogs.microsoft.com/commandline/d3d12-gpu-video-acceleration-in-the-windows-subsystem-for-linux-now-available/
Thanks Mike for the lesson, nicely done!
Cheers!