> but it let me improve my coding, thinking of solutions and the understanding behind game engines.
I think that's a great thing
building engines just for the fun of it or just to improve coding ability and gain knowledge is a great goal
here's a good tutorial with LWJGL (Light Weight Java Game Library) -- although its version 2 and LWJGL has made a big jump to version 3
https://www.youtube.com/playlist?list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP
I've SLOWLY been going through them and converting them to C++ and GLFW just so I can improve my coding and gain knowledge
but if I wanted to make a game I'd just go with Unity or Godot or libgdx or any other good prebuilt engine
Graphics programming is certainly not hands-off.
GLFW provides a simple API for creating windows, contexts and surfaces, receiving input and events. GLEW provides access to OpenGL extensions.
So neither GLFW nor GLEW directly render anything for you in a hands-off way. OpenGL provides the API you need to do the rendering with, and it is at a higher level than newer APIs like Vulkan but doing anything complex still requires significant programming effort.
"being able to make it cross platform" is often about the right choice of supporting libraries rather than the "making it cross platform skill", unless you're doing something like programming OpenGL without using a helper library (like GLFW).
If it's C/C++ you are using, i would recommend GLFW.
"GLFW is a free, Open Source, multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time. It is intended to be simple to integrate into existing applications and does not lay claim to the main loop."
at a very high level:
So at a high level you need openGL or Vulkan or direct3d to talk to your 3d card, give it vertices and shaders and textures.
But you need a window from the operating system to draw the results to, and you need some way to get input and play sound. You can either get that directly from the operating system or from cross platform apis like SDL2/GLFW or game engines/frameworks (Which in turn may use those apis, or something similar behind the scenes)
At a glance I found this tutorial. If you want to look into other frameworks, GLFW is better maintained and has a slightly more modern API style.
I'd recommend GLFW which is a much smaller library than SFML and SDL because it only does 2 things - give you a rendering context, and let you access input from mouse/keyboard/controller. SFML and SDL are full 'media' libraries and give you windowing and input, but also audio, multithreading, timing, file I/O, networking (SFML) and more. GLFW is just the bare bones that you need.
18.2 is also based on Xenial. Mint follows the LTS releases.
It is in theory possible to install packages from other releases -- it depends how intricately they are coupled to other packages in the system and whether their dependencies are different.
In a situation like this it's best to look for a PPA which provides a backport, but unfortunately there doesn't seem to be one for this package.
You can try to install the Yakkety package(s) manually using dpkg
, after downloading the .deb
file(s) from the Launchpad page -- but be aware that this may not work. There seem to have been some changes in the build dependencies, so even if the package gets installed, it may not work correctly.
Edit: I don't normally recommend installing from source, but this may be a good time to install from source.
Have you read through this one also? http://www.glfw.org/docs/latest/build.html
Simplify as much as possible. Get rid of as much as you can until you get something to build and run. Do not include windows.h.
The version of glfw you are using does come with built libraries correct?
Go to the following page:
http://www.glfw.org/download.html
Download Windows 32-bit Binaries (even on 64-bit), extract somewhere useful, and copy the contents of lib-mingw to your build folder or your Mingw installation/bin.
Note: I'm just trying this myself now. Will update.
Edit: building opengl-graphics on Windows seems to be broken. It's due to gl-rs naively assuming it's running on Linux and has all the amenities that Linux provides.
You could also try out GLFW, which is similar to GLUT that you mentioned, but does not lay claim to the loop and has excellent documentation (also, it's much cleaner and 'fresher' imo).
I think the "Display 1" and "Display 2" are only talking about the monitors themselves, not which GPU to render on. Normally if you select a monitor that's connected to an IntelHD4000 it will use that GPU to render, and if you select a display on the GeForce it will use that GPU to render. The commenter above was talking about building a program to let you select a display and having a GPU that was not connected to that display render the output
FYI the "choose your display" menu items are just using something like this to poll a list of available displays: http://www.glfw.org/docs/latest/monitor_guide.html
Many use GLFW for a light weight alternative since it doesn't do the many things that SDL does that are unrelated to OpenGL development itself. If you're doing only 3D stuff in OpenGL then SDL might be an overkill. See this SO post.
Welcome to nightmare of dependency and library management!
If you want to learn the graphics pipeline you really should stick to OpenGL (and subsequently C++). To do this out of the box you could download the latest version of Qt with openGL support, and use Qt's OpenGL wrapper library.
http://doc.qt.io/qt-5/qtopengl-index.html
If you would rather use a more traditional OpenGL wrapper you can check out GLFW and follow along a tutorial like this. GLFW will have more extensive documentation as it is widely used and Qt's openGL support is fairly new. Qt in general though has a ton of documentation.
On a side note setting up an ide and libraries is much easier on linux. Visual studio for example makes it a pain in the ass to import libraries into a project. In linux with gcc/make you just install the library (debian, sudo apt-get install glfw) and add a line to a makefile.
INCLUDES = -I$(glfw_inc) LIBRARIES = -L$(glfw_lib)
I'm on Ms Windows 7
I took the example code from here
http://www.glfw.org/documentation.html
and named it glfw_example.cpp
I compiled it with this
C:\Programs\gcc\bin\x86_64-w64-mingw32-g++.exe -m64 -std=c++11 -Wall -g -Werror -I C:\Programs\GLFW\include -L C:\Programs\GLFW\lib C:\Programs\GLFW_example.cpp -o main.exe -lglfw3dll -lopengl32
the contents of C:\Programs\GLFW\lib
glfw3.dll libglfw3.a libglfw3dll.a
the contents of C:\Programs\GLFW\include\GLFW
glfw3.h glfw3native.h
my compiler is
MinGW Builds 6.1.0 (64-bit)
and came from here (clicking on the link will automatically start the download)
the main site for the compiler is here http://mingw-w64.org/doku.php/download
I don't know what else to say
see these ?
https://www.youtube.com/playlist?list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP
translate all the java code to C++ and GLFW and modern opengl
don't stop until you've translated all the videos
>"being able to make it cross platform" is often about the right choice of supporting libraries rather than the "making it cross platform skill", unless you're doing something like programming OpenGL without using a helper library (like GLFW).
GLFW only takes care of context vreation, input and windowing. Yes, it's definitely helpful in abstracting out that particular area.
Making a game/game engine cross platform with OpenGL, though, is actually a lot of hard work regardless of whether or not you use GLFW or SDL. The amount of work in comparison between the two makes input handling windowing almost negligable in comparison.
At the end of the day, you're at the mercy of the driver implementation of OpenGL's specification.
When you download a library, you usually get an include folder and a library folder. There are 3 major ways libraries are: Header only, which means you only need the include folder since the implementation is inside the header files. Then there is static libraries, where you have to link to the library, but the library will be contained inside the binary you are compiling. Then there is dynamic libraries, where you have to link the library, but the library is not contained in the binary, so you have to use a DLL file (dynamic link library).
Then there are dependencies, where one library depends on another, so you have to link them both. But you have to link them in the correct order, which is first the library that depends on the other library, then the other library. So in our case, glfw depends on opengl32, glu32 and gdi32. And glew depends on opengl32 and glu32.
This is frustrating at first, but you'll get better with it the more you fiddle with it. I recommend you to read about the 3 stages of the compiler; preprocessor, compiling and linking. Maybe even try to compile some simple programs in the command line.
For creating a window, try the GLFW docs directly: http://www.glfw.org/docs/latest/intro.html . For the rest, there is probably no tutorial that will cover ALL those concepts, but if you Google Vertex Buffer Objects (for mesh rendering) and normal, diffuse, displacement maps separately, you will surely find plenty of tutorials on how to program those shaders.
The guide on the GLFW site is C, but is easily implemented in lwjgl3: http://www.glfw.org/docs/latest/quick.html
It gives you a pretty good idea of how to set up a window and such.
You could also look at the demos in the src/tests/org/lwjgl/demo folder in the project root!
This seems excellent - I'm a fan of cross platform, minimal, C libraries for sure.
But I'm curious about the overlap with glfw. Seems like the only thing ccore provides that glfw doesn't is threading support. Seems substantially younger that glfw too.
Cheers!
Ah, OpenGL 1.1 and GLUT. Partying like its 1998.
In case anyone cares, today you should probably go with SDL2 or GLFW. Both of those libraries support desktop, mobile, and even the web via emscripten. They are just as simple to use as GLUT, but are far superior in an innumerable amount of ways. You should NEVER use GLUT in your application.
Using OpenGL 1.x stuff isn't recommended nowadays either.
Hm... strange... well, you could try setting the context to be forward-compatible, maybe that'll make things work... although I can't imagine why OSX would require you to declare forwards-compatibility? That's not normally a thing people use anymore.
Also strange because if that was the case, the author of the tutorials would've surely noticed that not working and set the forwards-compatibility bit in the code?
At any rate, here's how you do it, try it out:
http://www.glfw.org/docs/latest/window.html#window_hints
set the hint GLFW_OPENGL_FORWARD_COMPAT to true (GLFW_TRUE or whatever) before you create the window.
If that still doesn't work, maybe it's just GLFW being buggy. I've had a few issues with GLFW on OSX before (but that was GLFW2.x...)
You use the callback provided by glfw, which is glfwSetCursorPosCallback. Documentation can be found here: http://www.glfw.org/docs/latest/group__input.html#ga7dad39486f2c7591af7fb25134a2501d
As full example I have during bootup of my program:
> glfwSetCursorPosCallback(window, CBMouseMove); // you do this once
and then a function:
> void Input::CBMouseMove(GLFWwindow* window, double posX, double posY) { // do stuff here }
have a look on GLFW:
http://www.glfw.org http://www.glfw.org/documentation.html
modern and portable library for managing windows/input/many other things with OpenGL.
if you will google for more guides, be sure you are reading about 3rd version
The vast majority of the dependencies in my C++ game are pure C.
try this link . I setup a basic glew/glut program which does nothing.
Unzip it to your msys 'home' directory and type 'make'. If it doesn't work, there may be something wrong with your compiler/overall setup. If it does work, read below.
To check what it is you forgot to do, open the 'makefile' file and compare the compile arguments with the ones generated by your IDE (assuming you know how it works...i'm not sure how pro you are). I shoved everything in the root folder just for testing purposes...don't do this.
^ i don't really know what i'm doing myself but having a working version to compare against helps
in any case, i would still reccomend using glfw because it gives you more control over your program, and is being developed even today unlike glut.
lol it looks like he uses GLFW as a (very basic) opengl windowing system, since that is what the window is called when when it is first opened.
also, openal is one of the dlls in the install directory so he's using that, too.
no idea what you're using for fonts/typesetting in game since i know glfw doesn't support fonts by default
> I hate libraries that co-opt my main(), and I loathe libraries that pretend to not co-opt my main() while actually doing so.
Bloody this. Have you tried GLFW? Much less of a headache and if you dig into the actual source code for any reason, it's much more readable than SDL. (Otherwise, what do you use?)
> That's why I asked. What draws UI though? TornadoFx or something else?
Koge is using GLFW to create the UI. GLFW is an Open Source, multi-platform library for creating windows with OpenGL contexts and receiving input and events.
> if c++ and opengl is a viable option
Sure, if you want to use C++ and OpenGL, just pick a windowing library and have at it. I use GLFW personally as it provides basic support for cross-platform windowing and keyboard/mouse input, then gets out of my way so I can deal with other tasks (like image loading, font rendering, audio, etc) on my own. That way, I can set things up to behave the way I want them to work. Many people prefer SDL or SFML though, which provide more features out of the box.
> I love programming so if making my own engineer is worth the challenge, I'm willing to face it.
If you just want something to tinker on as a hobby, it's a fine way to go. You can really dig into all aspects of the system, and understand how and why libraries were designed the way they were as you try to figure out how to integrate different components and write your own. Solving those kinds of challenges will make you a better, more knowledgeable programmer.
That said, if you instead really want to make a game, and don't care as much about tinkering around and experimenting and research, it's not necessarily the best choice as you can easily end up going down some deep rabbit holes that really have absolutely nothing to do with the specifics of your game. Creating content (graphics, music, story, level design, etc.) is usually the hard part of making 2D games these days, once you get over the initial hurdles of learning to program; if you really want to have a finished product at the end of your efforts -- something you can actually show for your time and say "See, look! I made a game!" then going down those rabbit holes is not very productive, since you're studying the wrong subject.
Basically, what's best to use depends on what you want to get out of it.
There are default values for all hints. Setting red bits to 8 does nothing, as that's the default for that hint (I'm assuming the above is a typo and you meant GLFW_RED_BITS
).
Choosing an OpenGL profile does matter, though. A lot of legacy functionality is unavailable if the core profile is selected.
In C++, yes. Using the same APIs in a language like python results in much less code because memory management is handled by the runtime.
That aside, have a look at glfw: http://www.glfw.org/documentation.html
hmm, i don't use mac so this will be a little different. Follow this to get your glfw binaries: http://www.glfw.org/docs/latest/compile.html#compile_deps_xcode
glad is compiled by your application so just download it and add in your source: http://glad.dav1d.de/
then this cmake will find and add OpenGL but you will need to add the link library as im not sure what the name is on Mac, could be GL as it is on linux.
find_package(OpenGL REQUIRED) include_directories(${OPENGL_INCLUDE_DIR}) link_directories(${OPENGL_LIBRARY})
Well for a concrete exemple you could take a look at how a window is created using both libraries. In SFML it's pretty straightforward, you create a sf::Window object, you can wrap it, and it'll be destroyed when it goes out of scope. In GLFW on the other hand, you have to call glfwCreateWindow that returns a pointer, and then call glfwDestroyWindow when you are done with it. When binding stuff with luabind I have to make sure that each object can be held inside a shared_ptr in order to be properly GC, so I would need to write a wrapper for GLFW while SFML works out of the box. By more object oriented I mean that I prefer having the full object ownership as oppose to having a reference to it. Also as mentioned above, having a sf::Event object instead of callbacks.
Ok this is getting weirder every minute... I wanted to print out the loaded extensions with the following code:
std::vector<const char*> extensions; unsigned int glfwExtensionCount = 0; auto glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); for (unsigned int i = 0; i < glfwExtensionCount; i++) { std::cout << glfwExtensions[i] << std::endl; extensions.push_back(glfwExtensions[i]); }
After executing the program nothing got printed to the console. So I tried to print out the number of loaded extensions, glfwExtensionsCount
. This returned 0
which seemed quite strange to me. The official glfw documentation stated the following:
> const char** glfwGetRequiredInstanceExtensions ( uint32_t * count )
> [out] count
Where to store the number of extensions in the returned array. This is set to zero if an error occurred.
So I tried to check the result of glfwVulkanSupported()
to check if GLFW could find the Vulkan loader. This returned GLFW_FALSE
which equals 0
.
After this I took my old code which was made with the vulkan-tutorial.com (it uses GLFW) and tried to debug it. The glfwGetRequiredInstanceExtensions(...)
function returned
VK_KHR_surface VK_KHR_xcb_surface in this program.
EDIT: So I am currently working on fixing some GLFW issues, maybe they are the cause.
Sorry I know you're holding my hand through this, and I appreicate it!
That worked properly, and now I'm stuck speculating how to make it function with the example code http://www.glfw.org/documentation.html
Does it have to be set up through the CMake app? How can I compile/run that code with sublime & terminal, or include it in a makefile. Thanks again!
LWJGL 3 uses GLFW for input so you can check those docs.
GLFW callbacks in LWJGL work by extending one of the callback classes / interfaces or passing lambda functions. See for example the getting started guide.
Well I've managed to link the libraries now and I can run the following code:
// include standard headers
// include GLEW
// include GLFW
int main () { // code return 0; }
however when I try and replace the above with the code from this tutorial http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/ and http://www.glfw.org/documentation.html it won't build. I just copied and pasted everything in both cases just to make sure that everything is working correctly and not only will it not build but it won't give me any error codes.
As protestor said, it's best to use a windowing toolkit for this stuff unless you're interested in implementing it manually.
The one I use for my OpenGL projects is GLFW. I highly recommend you check it out. And since it's open source, if you want to find out how it's done, you can!
There are many libraries intending to help with platform specific stuff like window creation. Creating a window in GLFW should as simple as sample code in http://www.glfw.org/documentation.html describes.
Thank you for the feedback! I looked into the documentation and found this. After doing pkg-config --static --libs glfw3
I ended up having to add a whole slew of libraries to get it to make
. My current compiling Makefile consists of the following:
all: g++ window.cpp main.cpp -o Onion -lglfw3 -lrt -lXrandr -lXinerama -lXi -lXcursor -lGL -lm -ldl -lXrender -ldrm -lXdamage -lX11-xcb -lxcb-glx -lxcb-dri2 -lxcb-dri3 -lxcb-present -lxcb-sync -lxshmfence -lXxf86vm -lXfixes -lXext -lX11 -lpthread -lxcb -lXau -lXdmcp
> pip install glfw
this command only installs the python bindings to glfw(which are unneeded as gumpy includes them) not the glfw library itself. Go here to install glfw.
> using glew and freeglut
If you're looking to make something outside your class in OpenGL from scratch using c/c++, try glfw for setting up the window/opengl environment. Their example code shows how simple it is.
Did you try GLFW? Here is the site -> http://www.glfw.org/
I've been using it for quite some time now with my openGL programs and I'm completely satisfied. It's extremely easy to use and if you have any problems understanding the docs you can take a look at the samples as well -> https://github.com/glfw/glfw/tree/master/examples
I went here and clicked the download link. It's GLFW 3.1.1 for windows 64bit (at least for me it was). That gives you a whole bunch of different lib folders and an include folder (as well as some others). I simply copied the files from the include folder, and copied the files in the folder titled "lib-vc2013". My computer is Windows 8.1 64 bit.I'm running Visual Studio Community 2013.
Looks like they are using the GLFW library. You can find the documentation just by googling the function name if you're lucky, like I did. Not sure if the actual source code is available though.
I've just tried compiling your code (from here) using your Makefile, and it seems to run fine... The mouse-look is smooth, although a bit slow for my mouse sensitivity (easily changed with the mouseSpeed
variable in controls.cpp
). No sign of the app running slowly (especially not 2-3fps), although the cursor does take a few milliseconds to jump back to the centre of the window.
A couple of things to try:
Your Makefile is linking in GLFW statically (with -lglfw3
), which is why you need all the additional -lXrandr -lXxf86v ...
stuff. It is much easier to link dynamically with -lglfw
, which would simplify the dependencies a bit. It could be that you have different versions of glfw installed for static vs dynamic linking (I did this recently when building it from source), and one of them has a bug. This is potentially a difference between your Makefile and the CMakeLists.txt.
Are you using an up-to-date version of GLFW? The CMakeLists.txt below seems to reference version 3.0.3, but the latest stable version is currently 3.1.1.
You might also want to disable VSync (glfwSwapInterval
) in case that is adding unwanted latency.
Please note, however, that this method of implementing mouse-look controls is explicitly discouraged and unsupported by GLFW. See http://www.glfw.org/docs/latest/input.html#cursor_mode for details on how to do it the intended way, which may well fix all of your problems.
Okay, that really explains the problem... (That's why we need exact error messages :) You have GLFW3 external library not yet installed. ("cannot find -lglfw3") Download and install pre-compiled binaries first.
Check out GLFW it's a pretty solid library for creating a window in opengl 3. Especially on osx, as other windowing libraries don't allow for opengl 3 on osx, or at least I couldn't get them working properly.
I used the 6th edition of this book and it used opengl. "Interactive Computer Graphics with WebGL" But webgl shouldn't be too far off as it requires a fragment and vertex shader before you can actually draw anything.
Looks like the tutorial you're working with is using GLFW 2.X. When version 3 came out they changed the API a ton, which is what's causing your compilation problems. For the most part, the function names are all the same, but they take a GLFWwindow
argument instead of just working with the current window.
You can find the reference documentation here. Just look for any of the functions that are throwing errors and see what the new version of the functions look like.
I'd recommend trying out http://www.glfw.org/ in place of GLUT as this will give you control over your main loop, from there there are multiple ways of capturing an image from your render, such as FBOs, glReadPixels, or a third party library with it built in (SOIL does it for example). Good luck!