c++ - Drawing 2D stuff with SDL_Renderer and OpenGL stuff with SDL_GLContext -


i have been learning sdl 2d programming while , wanted create program using sdl , opengl combined. set this:

sdl_init(sdl_init_video);  window = sdl_createwindow("sdl , opengl", sdl_windowpos_centered, sdl_windowpos_centered, width, height, sdl_window_opengl);  context = sdl_gl_createcontext(window); 

the program black window white line displayed using opengl. here code rendering:

glclearcolor(0, 0, 0, 0); glclear(gl_color_buffer_bit);           glbegin(gl_lines);      glvertex2d(1, 0); glvertex2d(-1, 0); glend();  sdl_gl_swapwindow(window);   

so thing is, render textures additionally using pure sdl , sdl_renderer object, did before without opengl. tried out didn't work. possible , how? did creating sdl_renderer , after drawing opengl stuff doing this:

sdl_rect fillrect; fillrect.w = 50; fillrect.h = 50; fillrect.x = 0; fillrect.y = 0;   sdl_setrenderdrawcolor(renderer, 100, 200, 100, 0); sdl_renderfillrect(renderer, &fillrect);  sdl_renderpresent(renderer);     

but not work. rectangle not shown, although milliseconds appears slightly. feel opengl rendering overwriting it.

sdl uses opengl (or in cases direct3d) , opengl has internal state affects gl calls in program. current version of sdl not indicate states changes or depends upon call , not include functions reset known state. means should not mix sdl_renderer opengl yet.

however, if want functionality now, can try sdl_gpu (note: i'm author). support mixing opengl calls , custom shaders. want specify version of opengl api need (e.g. gpu_initrenderer(gpu_renderer_opengl_1, ...)) , reset gl state sdl_gpu uses each frame (gpu_resetrendererstate()). check out 3d demo in sdl_gpu source repository more.

https://github.com/grimfang4/sdl-gpu/blob/master/demos/3d/main.c


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -