SDL: Calling SDL_CreateRenderer Segfaults [duplicate] - c++

This question already has answers here:
SDL2 program only works if Renderer is created with SDL_RENDERER_SOFTWARE
(2 answers)
Closed 6 years ago.
When I use Software Rendering in my SDL2 project, everything works as expected.
e.g when the code for creating a SDL_Renderer looks like this:
this->renderer = SDL_CreateRenderer(this->window, -1, SDL_RENDERER_SOFTWARE);
When I use Hardware rendering, e.g when the code for creating a SDL_Renderer looks like this:
this->renderer = SDL_CreateRenderer(this->window, -1, SDL_RENDERER_ACCELERATED);
For some reason, calling SDL_UpdateWindowSurface results in a SEGFAULT. I call SDL_UpdateWindowSurface in a standard way:
// Update window surface
SDL_UpdateWindowSurface(window);
I know that the way my window is setup is correct, since running the program with a Software Rendering SDL_Renderer works just fine, and doesn't yield a SEGFAULT.
Does anybody have any idea what might be causing this? Has anybody experienced something like this before?

SDL_GetWindowSurace documentation says You may not combine this with 3D or the rendering API on this window.. Either generate surface and update window surface yourself (and forget about hardware acceleration) or use SDL_Renderer and never touch window surface (it doesn't even exist for accelerated backend).

Related

SDL_Renderer opengl conflict

I'm new to openGL and SDL and I'm having some problems with a basic program I wrote. I've narrowed it down and it seems like the problem is a conflict between the SDL_CreateRenderer function and how SDL manages OpenGL.
Basically the program is a simple game, drawn with OpenGL, and the problem has risen with me creating a menu. Since the game window was created with the "SDL_WINDOW_OPENGL" flag, I created another window for the menu. Whenever I need to switch between game and menu I just hide and show whichever window I need. To draw on the menu window though I need to create a renderer but after doing so, if I try to go back to the OpenGL window everything crashes catastrophically (computer slows down, everything is unresponsive...).
Can anyone guess where the problem could lie? Or can anyone suggest a better way to solve my game-menu problem?
Don't try to inter-op OpenGL and SDL_Renderer: even if you could guarantee that your platform did/did not implement SDL_Renderer in terms of OpenGL the SDL_Renderer API doesn't have any way to properly set/restore the OpenGL state that SDL_Renderer uses.

SDL resetting glViewport

I'm testing supporting multiple resolutions in an application using SDL2 with OpenGL. To create my "letterbox" functionality I set my glViewport to an appropriate value and everything works perfectly.
However, if I create my window with the SDL_WINDOW_ALLOW_HIGHDPI flag set, whenever I move my window (after receiving the SDL_WINDOWEVENT_MOVED event) SDL modifies the viewport to the full size of the window, which can be verified by calling SDL_GL_GetDrawableSize during the event.
If I do not set SDL_WINDOW_ALLOW_HIGHDPI when creating the window, the viewport is not reset. I do believe this to be a bug, but cannot find anything through the SDL bugzilla so I thought to ask if anyone has seen similar behavior.
You may need to have a retina MacBook Pro to experience this behavior.
Just do what you should be doing anyway: Always re-/set the viewport at the beginning of drawing each frame. As soon as you want to implement a HUD, use framebuffer objects or similar things you'll have to set the viewport (several times) for drawing each frame.

Use OpenGL without a window [duplicate]

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.

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.

No OpenGL context current on this thread at javax.media.opengl.glu.GLU.getCurrentGL

I encountered a similar problem when I started learning Opengl (JOGL) for the "GL2 gl" months ago.... and then I discovered how to solve (everything having something to do with "gl" should be called from within the display/init method).
After some time I also needed to use the "GLU glu" (for the gluOrtho2D). Therefore this problem arose again. But lets say that it wasn't such a big problem, because the program was running fine despite this error.
Unfortunately, it seems that now this problem has some annoying effects.. so I really would like to solve it.
Here some code:
...
GLU glu = new GLU();
public void display(GLAutoDrawable gLAutoDrawable) {
...
// map a 2D bild width*height on OpenGL
glu.gluOrtho2D(-width/2, (width+1)/2, -(height+1)/2, height/2);
}
The funny thing is that:
I have other glu calls in the display, like "glu.gluLookAt(0, 0, 1, 0, 0, 0, 0, -1, 0);" and I never got a problem there
It takes place only when I call a refresh from another thread ("glcanvas.display")
I already did many attempts like initialize it everytime in the display, or forcing the context with:
glu = new GLU();
gLContext = gLCanvas.getContext();
gLContext.makeCurrent();
but nothing so far worked:
Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: No OpenGL context current on this thread
at javax.media.opengl.glu.GLU.getCurrentGL(GLU.java:175)
at javax.media.opengl.glu.GLU.gluOrtho2D(GLU.java:1344)
I tried to move the getContext and the makeCurrent just before the glu.gluOrtho2D and it worked..