kiritow / miniengine Goto Github PK
View Code? Open in Web Editor NEWA C++ Mini Engine. Based on SDL2.
License: MIT License
A C++ Mini Engine. Based on SDL2.
License: MIT License
测试代码如下
#include <iostream>
using namespace std;
#include "MiniEngine.h"
#include "MiniEngine_Widget.h"
using namespace MiniEngine;
int AppMain()
{
Window wnd("Title",1280,768);
Renderer rnd=wnd.getRenderer();
Texture t=rnd.loadTexture("1.png");
Texture b=rnd.loadTexture("2.png");
rnd.clear();
rnd.copyFullFill(t);
rnd.update();
while(1)
{
SDL_Event e;
SDL_WaitEvent(&e);
if(e.type==SDL_MOUSEBUTTONDOWN) break;
}
cout<<"Changed"<<endl;
wnd.setRenderer(RendererType::Accelerated);
Renderer nrnd=wnd.getRenderer();
cout<<rnd.isReady()<<" "<<nrnd.isReady()<<endl;
nrnd.clear();
nrnd.update();
ErrorViewer ss;
ss.fetch();
cout<<ss.what()<<endl;
while(1)
{
SDL_Event e;
SDL_WaitEvent(&e);
if(e.type==SDL_MOUSEBUTTONDOWN) break;
}
nrnd.clear();
nrnd.copyFullFill(b);
nrnd.update();
ss.fetch();
cout<<ss.what()<<endl;
cout<<"Printed"<<endl;
while(1)
{
SDL_Event e;
SDL_WaitEvent(&e);
if(e.type==SDL_MOUSEBUTTONDOWN) break;
}
return 0;
}
根据当前情况,nrnd的建立会导致rnd的失效,此时rnd渲染的t和b都处于无效状态(Invalid Texture).
解决这个问题可以将Texture中的指针改为weak_ptr,并将真正的Texture放入Window类中. 但是这样的话又不能在Texture超出作用域的时候自动释放(因为都保存在Window里了),这样很有可能引起内存暴涨...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.