@@ -184,8 +184,13 @@ static GLuint loadShader(GLenum type, const char *filename) {
184184
185185 DEBUG (" Loading shader %s" , filename);
186186
187+ #ifdef __APPLE__
188+ char fb[1024 ];
189+ sprintf (fb, " %s/shaders/%s" , SDL_GetBasePath (), filename);
190+ #else
187191 char fb[256 ];
188192 sprintf (fb, " shaders/%s" , filename);
193+ #endif
189194
190195 FILE *file = fopen (fb, " r" );
191196 if (file == nullptr ) {
@@ -294,6 +299,7 @@ int init_opengl() {
294299 }
295300
296301 // Can we create the world rendering context?
302+ SDL_GL_SetAttribute (SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1 );
297303 context = SDL_GL_CreateContext (window);
298304 if (context == nullptr ) {
299305 ERROR (" Could not create an OpenGL context! Falling back to Software mode." );
@@ -444,21 +450,21 @@ void get_hdpi_scaling(int *x_scale, int *y_scale) {
444450 *y_scale = output_height / screen_height;
445451}
446452
447- void opengl_swap_and_restore () {
453+ void opengl_swap_and_restore (SDL_Surface *ui ) {
448454 // restore the view backup (without HUD overlay) for incremental
449455 // updates in the subsequent frame
450456 SDL_GL_MakeCurrent (window, context);
451- SDL_GL_SwapWindow (window);
452-
453457 glClear (GL_COLOR_BUFFER_BIT);
454458
455459 int x_hdpi_scale, y_hdpi_scale;
456460 get_hdpi_scaling (&x_hdpi_scale, &y_hdpi_scale);
457461
462+ // Set the drawable area for the 3d view
458463 glViewport (phys_offset_x * x_hdpi_scale, phys_offset_y * y_hdpi_scale, phys_width * x_hdpi_scale,
459464 phys_height * y_hdpi_scale);
460465 set_blend_mode (false );
461466
467+ // Bind and setup our general shader program
462468 glUseProgram (textureShaderProgram.shaderProgram );
463469 GLint tcAttrib = textureShaderProgram.tcAttrib ;
464470 GLint lightAttrib = textureShaderProgram.lightAttrib ;
@@ -468,6 +474,7 @@ void opengl_swap_and_restore() {
468474 glUniformMatrix4fv (textureShaderProgram.uniView , 1 , false , IdentityMatrix);
469475 glUniformMatrix4fv (textureShaderProgram.uniProj , 1 , false , IdentityMatrix);
470476
477+ // Draw the frame buffer to the screen as a quad
471478 bind_texture (backupBuffer.texture );
472479 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
473480 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -487,14 +494,25 @@ void opengl_swap_and_restore() {
487494 glVertex3f (-1 .0f , 1 .0f , 0 .0f );
488495 glEnd ();
489496
497+ // Finish drawing the 3d view
490498 glFlush ();
491499
492500 glUniform1i (textureShaderProgram.uniNightSight , false );
493501
494- // check OpenGL error
502+ // Check for OpenGL errors that might have happened
495503 GLenum err = glGetError ();
496504 if (err != GL_NO_ERROR)
497505 ERROR (" OpenGL error: %i" , err);
506+
507+ // Blit the UI canvas over the 3d view
508+ SDL_Texture *texture = SDL_CreateTextureFromSurface (renderer, ui);
509+ SDL_SetTextureBlendMode (texture, SDL_BLENDMODE_BLEND);
510+
511+ SDL_RenderCopy (renderer, texture, NULL , NULL );
512+ SDL_DestroyTexture (texture);
513+
514+ // Finally, swap to the screen
515+ SDL_RenderPresent (renderer);
498516}
499517
500518void toggle_opengl () {
0 commit comments