Tuesday, July 25, 2017

sdl - SDL2 with OpenGL -- weird results, what's wrong?



I'm porting an app to iOS, and therefore need to upgrade it to SDL2 from SDL1.2 (so far I'm testing it as an on OS X desktop app only). However, when running the code with SDL2, I'm getting weird results as shown on the second image below (the first image is how it looks with SDL, correctly). The single changeset that causes this is this one, do you see something obviously wrong there, or does SDL2 have some OpenGL nuances I'm unaware of? My SDL is based on the latest from HG.


Update: another question about the iOS port of the same project is here.


Update 2: this is now also on the SDL newsgroup: http://thread.gmane.org/gmane.comp.lib.sdl/58026


Update 3: I tried using Regal for portable OpenGL, the not-so-good result is on the third screenshot, produced merely by replacing


#include 
#include

with


#include "GL/Regal.h"
#include "GL/RegalGLU.h"


using SDL 1.2 using SDL 2 using Regal with SDL 2



Answer



Heres your problem notice I comment out the surface = SDL_Get... it was giving some weird results. Also you forgot to create the OpenGL context. Let me know if you have any other issues.


SDLWindow::SDLWindow(int width, int height, double axisLen, const std::string &caption)
:m_fov(axisLen)
,m_width(0)
,m_height(0)
,m_fps(0)
,m_idxSnapshot(0)

,m_camPos(0, 0, 2)
,m_camLookAt(0, 0, 0)
,m_camOrient(0, 1, 0)
,surface(NULL)
,m_texStar(0)
,m_bRunning(true)
{
SDL_GLContext ctx;

if (SDL_Init(SDL_INIT_VIDEO) < 0)

throw std::runtime_error(SDL_GetError());
atexit(SDL_Quit);

SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_RETAINED_BACKING, 1 );

if ((window = SDL_CreateWindow(caption.c_str(), SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
SDL_WINDOW_BORDERLESS)) == NULL)

throw std::runtime_error(SDL_GetError());

/*if ((surface = SDL_GetWindowSurface(window)) == NULL)
throw std::runtime_error(SDL_GetError());*/

m_width = width;
m_height = height;

ctx = SDL_GL_CreateContext(window);


InitGL();
}

No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...