当前位置:网站首页>Pits encountered by sdl2 OpenGL
Pits encountered by sdl2 OpenGL
2022-07-26 03:54:00 【Ke AI's eyes】
Novice use SDL2 It's time to create SDL_Renderer Renderers
Default SDL2 Renderer It seems to be used D3D( I'm not sure )
The corresponding display function is SDL_RenderPresent()
Then we opengl The corresponding display function is SDL_GL_SwapWindow()
After testing , The above two functions can display normally , But it can't be used together , Otherwise, it will flash
pit 1:SDL_RenderClear Use of functions
use SDL It's no problem to call the cleanup function when the default renderer
Use opengl Calling this later will erase the screen , Careful use
How to be in SDL2 Use in opengl
Start with initialization
// Set up SQL Version and information
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);And then in your SDL_CreateWindow Add the SDL_WINDOW_OPENGL, as follows
window = SDL_CreateWindow(p_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, p_w, p_h, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);Then create opengl Context , And initialization glad
SDL_GL_CreateContext(window);
SDL_GL_SetSwapInterval(0);
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress);Check where you created the renderer , Does your renderer support opengl
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
// Check for support OPENGL, If exit is not supported , Exit code 8
SDL_RendererInfo rendererInfo;
SDL_GetRendererInfo(renderer, &rendererInfo);
if (strncmp(rendererInfo.name, "opengl", 6)) std::cout << "88888" << std::endl;;
In this way, the initialization work is done
Explain it. , The above steps are to make the renderer support opengl
My original intention is to write before SDL_Renderer Rendering UI The part of is not disturbed , At the same time, introduce opengl, Fortunately, these two can work at the same time , It saves the trouble of rewriting .
pit 2 glad And SDL_opengl
Because I am also a beginner , It may not be right , Everyone criticizes learning
glad This third-party library can help us find opengl Function of
SDL_opengl Inside is sdl Self contained opengl Function of , You need to add opengl32 Otherwise, compile and report an error
The result of the current test is SDL_opengl The functions inside can be compared with sdl Good combination ,glad Can also be used, but with sdl The default rendering function conflicts .
I'm too lazy to write , To be continued
边栏推荐
- Oracle 11g "password delayed verification" feature
- Opencv learning notes - edge detection and Canny operator, Sobel operator, lapiacian operator, ScHARR filter
- Opencv learning notes -- Hough transform
- Three ways of redis cluster
- 申请SSL证书,并给域名配置SSL证书,并部署服务器;SSL证书的下载和安装
- SDL2 Opengl遇到的坑
- 涂鸦幻彩产品开发包如何使用
- 让百度收录,爬虫自己网站
- 5-20v input peak charging current 3.5A single lithium battery switching charging chip sc7101
- PHP implements the algorithm of adding from 1 to 100
猜你喜欢

WAF details

CPU and GPU are out of date, and the era of NPU and APU begins
![[mathematical modeling - Summary of planning model] | matlab solution](/img/b0/a4d33d7d7b605b7cc6149b59b55fb8.png)
[mathematical modeling - Summary of planning model] | matlab solution

Opencv learning notes -- Hough transform

5年1.4W倍,NFT OG 的封神之路|Web3专栏

Can UDP and TCP use the same port?

General test case writing specification

基于移位寄存器的同步FIFO

Sersync/lsync real-time synchronization

Graduation season & harvest season, leave your beautiful moments
随机推荐
Zkevm: summary of zkevm and L1 by Mina's CEO
【单片机仿真项目】外部中断0和1控制两位数码管进行计数
php 保存数组到文件 var_export、serialize
【云原生之kubernetes】kubernetes集群下ConfigMap使用方法
Oracle 11g "password delayed verification" feature
电商运营小白,如何快速入门学习数据分析?
WAF details
6年从零开始的自动化测试之路,开发转测试我不后悔...
FPS game reverse - box Perspective (matrix)
Six years of automated testing from scratch, I don't regret turning development to testing
想要做好软件测试,可以先了解AST、SCA和渗透测试
General test case writing specification
Find my technology | the Internet of things asset tracking market has reached US $6.6 billion, and find my helps the market develop
In PHP, you can use the abs() function to turn negative numbers into positive numbers
Find My技术|物联网资产跟踪市场规模达66亿美元,Find My助力市场发展
Navicat connects to MySQL database on Cloud Server
Dracoo master
Multi merchant mall system function disassembly lecture 15 - platform side member label
深度学习之SuperViT
cpu和gpu已过时,npu和apu的时代开始