Use OpenGL without a window [duplicate] - c++

This question already has answers here:
Can you create OpenGL context without opening a window?
(3 answers)
Closed 8 years ago.
I want to use the nice z-buffer functions of OpenGL, but I really don't want my program to open a window each time it runs (because I want it run as fast as possible).
I am quite new to OpenGL, and I followed the tutorial to learn it. In the tutorial every example starts with:
initialize GLFW
open a window
initialize GLEW
the real stuff
So I was thinking: hmm, since I only want to keep the real stuff, let's get rid of step 1-3. --I ended up with "segmentation error"
Then I was thinking: well, maybe GLEW is related to my real stuff, but GLFW, by its name, only does the window stuff. So I tried deleting step 1, and deleting step 1-2. --Both gave me a "failed to initialize GLEW"
Now I'm confused... What should I do?

I use OpenGL with GLFW + GLEW in a multi-platform system [Windows, Mac and Linux].
The error you are having smells like missing:
glewExperimental = GL_TRUE;
Google for it so you can understand a little more.
What platform are you on?

Unless I'm confused, GLFW is also responsible for setting up the OpenGL context which you will need regardless if you want to render the buffers to screen or not.

Related

Multisampled framebuffer in OpenGL under Windows

How do I set the number of samples in the default framebuffer, given by Windows?
I found this page, but although I use glew, there is no available wglChoosePixelFormatARB function in my context. What could be the cause of this?
With WGL, you can only set the pixel format for a window once when you create the context, and you can only call the wglChoosePixelFormatARB() function once the client driver is loaded, and the client driver is only loaded once you have an OpenGL context. Yes, that's circular. So, this means you have to do the following:
Create a window with an OpenGL context.
Get the function pointer for wglChoosePixelFormatARB().
Destroy the window, and create a new window with the desired pixel format.
If you've got any sense in you, you'll use SDL or GLFW to do this for you, because it's just a bunch of plumbing you have to write, there's no value in learning how to do it, and you probably want to get some real work done. SDL/GLFW/etc. is how 99% of the OpenGL game devs out there do it.
If you really want to do this yourself and get stuck, look at the SDL or GLFW source code to see how they do it.
In SDL, the src/video/windows/SDL_windowsopengl.c file has a function WIN_GL_ChoosePixelFormatARB() which does what you want. Also note the function WIN_GL_LoadLibrary().
In GLFW, the src/win32_window.c file has a function _glfwPlatformCreateWindow() which does what you want.
P.S. GLEW is a bit broken with core contexts and modern cards, so watch out. There are other GL loaders out there.

Using SDL, OpenGL and Qt together

For a while I've been using SDL to write my 3D engine,and have recently been implementing an editor that can export an optimized format for the type of engine Im building. Right now the editor is fairly simple, objects can just be moved around and their textures and models can be changed. As of right now, I'm using SDL with OpenGL to render everything, but I want to use Qt for the GUI part of the editor, that way it looks native on every platform. I've got it working great so far, I'm running a QApplication inside of the SDL application, so it basically just opens 2 windows, one that uses SDL and OpenGL, and the other using Qt. Doing a bit of research, I've found that you can manually update a QApplication, which totally removes any threading problems, and everything works. Just in case you're having a hard time visualizing this, heres a picture:
What my goal is to merge these windows into one, because on smaller screens (like my laptop's) it makes it really hard to keep track of all the different windows that I would eventually have. I know theres a way to render to Qt with OpenGL, but can this be integrated with SDL? Am I going to need to move away from using an SDL window and use a QT one if the editor is enabled? Just to clarify, when the engine isn't in editor mode, it won't use and Qt, just SDL, so optimally I wouldn't need to do this.
Drop the SDL part. You have Qt, which does everything SDL does as well. Just subclass a QGLWidget and use that.
You can keep your game and editor separate processes and still make them part of the same app.
Just spawn the window where you want the game to run as part of Qt, and at least in windows, you can then pass the window handle to your game, and make sure when your game is setting up, instead of creating the window yourself in SDL and binding the opengl context to it, you can actually bind to the existing handle.
There are some gotchas with this technique to watch out for such as input focus I believe (I tested with directX, but it might be similar with SDL). The problem is that the foreground mode does some dumb checks on the "root" window which for me was not the window that owned the opengl context, so it failed to initialize. However background mode worked. I think that was for a joystick now that I think about it, but anyway, that's how you can merge everything together.

Fullscreen with opengl

I need my window to be set to fullscreen (fs). No border, no interaction with anything behind this window, no start bar,etc. Just the program i'll be working in.
I'm guessing that the cursor not going outside of the window is not part of this, but i'll work on that later.
I've seen and tried the NeHe tutorial, but since it was wrote almost 10 years ago, i was wondering if a "less-line" way of putting a program fs exist.
"less-line" way of putting a program fs exist.
Use glut or SDL and initialize them in fullscreen mode. Can't get less lines than that.
Otherwise read this.

Combine WGL with GLUT for shapes under Windows 7 OpenGL. Missing GLUT INIT?

I'm working with OpenGL using Win32 API. Therefore I'm using wgl (Wiggle). Everything is fine. Except if I want to use some shapes from the FREEGLUT library. For example, the teapot. I was looking at the source code of freeglut, and it seems that when I issue a
glutSolidTeaPot(1.0); ,it exists the program because of the macro: FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" ); which calls fgerror, which has an exit(1).
Therefore, the symptom that I'm getting is obvious. When I ran the OPENGL program without any GLUT commands (like the teapot) it works great. If I use the teapot, it exits.
It is clear to me, that I'm missing initialization. The question is if I can initialize (and how) glut to be used for the shapes in my wgl context ... If this is not possible, I guess I could create the shapes myself. It is just faster to use those if possible.
All the examples that I have found so far point in how to initialize glut when you are working with glut only.
I'm using Windows 7 64, Visual Studio 2012, NVIDIA 330m , FreeGlut
FreeGLUT is not intended to be used in part. It is a system for creating and managing an OpenGL rendering context. It has utilities functions, but it's primary purpose is to create and manage a window. So if you're not using FreeGLUT to create and manage OpenGL, you don't get to use it for other things too.
While It seems that combining GLUT and WGL (Wiggle) is not possible (and rightly so), I have look at the code and it seems that this could be change to make it work. Of course, why make it work? Because of the additional utilties that GLUT (FreeGlut) has... like creating a sphere...
A better approach is to create a modern library to do all of this... Of course, you have some of the geometry libraries outthere, but I haven't check them.
I'm talking something more like the AUX library, but up to date.

OpenGL texturing

Sorry for the plea for help, but I am frustrated.
I don't know why, but I've never seemed to be able to get texturing to work in OpenGL. I would really appreciate a minimal example, so long as it only uses /gl.h /glu.h and standard C++ libraries. Any other insight would be appreciated.
Sorry for simply asking for you to write up a whole program for me, but I could really use it, since EVERY internet example I have seen uses glut. I can't compile it for some reason, and it is very annoying.
Thanks.
You NEED some library or interface to create an OpenGL context (and a window to display it).
GLUT is outdated, but still popular; good options nowadays are GLFW or SDL. I recommend GLFW.
(BTW, why did you even need to compile GLUT? Doesn't it have precompiled binaries for Windows?)
Or you can use system-specific functionality; in your case - WinAPI. However, this is a very tedious process; much unlike the portable solutions which create a window in just one or two lines of code and provide easy input handling.
Once you get your GL window up and running, you can learn texturing (or anything else) from any tutorial. The OpenGL calls will be the same, it doesn't matter how the window was created.
Here's a good tutorial:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06
This code does not use glut.
You need a window manager to create a window, for which you are going to create a context, where you can render your image. You can not do that using standard c++.
It is not clear for which OS you are targeting, but there are cross-platform frameworks, like GLUT, SDL, etc. You can also do it using xlib, if you are on linux.