mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa ToggleFullScreen
This commit is contained in:
parent
c095ff3407
commit
cdff5cc0f8
@ -17,7 +17,7 @@ namespace xna {
|
||||
adp->_index = 0;
|
||||
adp->_adapter = pAdapter;
|
||||
|
||||
return std::move(adp);
|
||||
return adp;
|
||||
}
|
||||
|
||||
pFactory->Release();
|
||||
@ -239,5 +239,15 @@ namespace xna {
|
||||
collection->_displayModes = displayList;
|
||||
|
||||
return std::move(collection);
|
||||
}
|
||||
|
||||
bool GraphicsAdapter::GetOutput(UINT slot, IDXGIOutput*& output) {
|
||||
if (!_adapter) return false;
|
||||
|
||||
|
||||
if (_adapter->EnumOutputs(slot, &output) != DXGI_ERROR_NOT_FOUND)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -27,7 +27,8 @@ namespace xna {
|
||||
virtual Uint SubSystemId() const override;
|
||||
virtual Uint VendorId() const override;
|
||||
virtual UDisplayModeCollection SupportedDisplayModes() const override;
|
||||
virtual constexpr bool IsDefaultAdapter() const { return _index == 0; }
|
||||
virtual constexpr bool IsDefaultAdapter() const { return _index == 0; }
|
||||
bool GetOutput(UINT slot, IDXGIOutput*& output);
|
||||
|
||||
public:
|
||||
IDXGIAdapter1* _adapter{ nullptr };
|
||||
|
@ -75,16 +75,16 @@ namespace xna {
|
||||
ID3D11DeviceContext* _context{ nullptr };
|
||||
IDXGIFactory1* _factory = nullptr;
|
||||
PSwapChain _swapChain{ nullptr };
|
||||
PGraphicsAdapter _adapter{ nullptr };
|
||||
PRenderTarget2D _renderTarget2D{ nullptr };
|
||||
PBlendState _blendState{ nullptr };
|
||||
xna::Viewport _viewport{};
|
||||
|
||||
private:
|
||||
unsigned int _createDeviceFlags{ 0 };
|
||||
D3D_FEATURE_LEVEL _featureLevel{ D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0 };
|
||||
float _backgroundColor[4] = { 0, 0, 0, 0 };
|
||||
xna::PresentationParameters _presentParameters;
|
||||
PGraphicsAdapter _adapter{ nullptr };
|
||||
PRenderTarget2D _renderTarget2D{ nullptr };
|
||||
xna::Viewport _viewport{};
|
||||
PBlendState _blendState{ nullptr };
|
||||
bool _usevsync{ true };
|
||||
|
||||
bool createDevice();
|
||||
|
@ -33,7 +33,12 @@ namespace xna {
|
||||
|
||||
}
|
||||
|
||||
int Game::Run() {
|
||||
void Game::Exit()
|
||||
{
|
||||
_gameWindow->Close();
|
||||
}
|
||||
|
||||
int Game::Run() {
|
||||
Initialize();
|
||||
|
||||
if (_graphicsDevice == nullptr) {
|
||||
|
@ -15,7 +15,8 @@ namespace xna {
|
||||
virtual ~Game() override {
|
||||
}
|
||||
|
||||
virtual void Exit() override{}
|
||||
virtual void Exit() override;
|
||||
|
||||
virtual int Run() override;
|
||||
|
||||
virtual PGameWindow Window() override {
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "game-dx.hpp"
|
||||
#include "window-dx.hpp"
|
||||
#include "gdeviceinfo-dx.hpp"
|
||||
#include "adapter-dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
GraphicsDeviceManager::GraphicsDeviceManager(Game*& game) : _game(game) {
|
||||
@ -29,23 +30,31 @@ namespace xna {
|
||||
}
|
||||
|
||||
void GraphicsDeviceManager::ApplyChanges() {
|
||||
//_game->_graphicsDevice = _device;
|
||||
}
|
||||
|
||||
void GraphicsDeviceManager::ToggleFullScreen() {
|
||||
if (!_game || !_game->_graphicsDevice || !_game->_graphicsDevice->_swapChain)
|
||||
return;
|
||||
|
||||
auto& swap = _game->_graphicsDevice->_swapChain;
|
||||
|
||||
BOOL state = false;
|
||||
swap->_swapChain->GetFullscreenState(&state, nullptr);
|
||||
swap->_swapChain->SetFullscreenState(!state, nullptr);
|
||||
}
|
||||
|
||||
void GraphicsDeviceManager::CreateDevice(GraphicsDeviceInformation const& info) {
|
||||
_device = New<GraphicsDevice>(info);
|
||||
//auto window = _game->Window();
|
||||
_device->Adapter(info.Adapter());
|
||||
auto window = info.Window();
|
||||
|
||||
window->Size(_backBufferWidth, _backBufferHeight);
|
||||
|
||||
if (!window->Create()) {
|
||||
MessageBox(nullptr, "Falha na criação da janela", "Xna Game Engine", MB_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
//_device->Initialize(*window);
|
||||
|
||||
if (!_device->Initialize(*window)) {
|
||||
MessageBox(nullptr, "Falha na inicialização do dispositivo gráfico", "Xna Game Engine", MB_OK);
|
||||
return;
|
||||
|
@ -37,14 +37,14 @@ namespace xna {
|
||||
virtual void ChangeDevice() override;
|
||||
|
||||
public:
|
||||
static constexpr int DefaultBackBufferWidth = 1280;//800;
|
||||
static constexpr int DefaultBackBufferHeight = 720;// 480;
|
||||
static constexpr int DefaultBackBufferWidth = 800;//800;
|
||||
static constexpr int DefaultBackBufferHeight = 480;// 480;
|
||||
|
||||
private:
|
||||
Game*& _game;
|
||||
Game* _game;
|
||||
Int _backBufferWidth{ DefaultBackBufferWidth };
|
||||
Int _backBufferHeight{ DefaultBackBufferHeight };
|
||||
bool _isDeviceDirty{ false };
|
||||
bool _isDeviceDirty{ false };
|
||||
PGraphicsDevice _device;
|
||||
};
|
||||
}
|
||||
|
@ -11,60 +11,78 @@ using namespace xna;
|
||||
// cout << "Hello CMake." << endl;
|
||||
// return 0;
|
||||
//}
|
||||
namespace xna {
|
||||
class Game1 : public Game {
|
||||
public:
|
||||
Game1() {
|
||||
auto _game = reinterpret_cast<Game*>(this);
|
||||
graphics = New<GraphicsDeviceManager>(_game);
|
||||
graphics->PreferredBackBufferWidth(1280);
|
||||
graphics->PreferredBackBufferHeight(720);
|
||||
}
|
||||
|
||||
class Game1 : public Game {
|
||||
public:
|
||||
Game1() {
|
||||
auto _game = reinterpret_cast<Game*>(this);
|
||||
graphics = New<GraphicsDeviceManager>(_game);
|
||||
}
|
||||
void Initialize() override {
|
||||
graphics->Initialize();
|
||||
Game::Initialize();
|
||||
}
|
||||
|
||||
void Initialize() override {
|
||||
graphics->Initialize();
|
||||
void LoadContent() override {
|
||||
spriteBatch = New<SpriteBatch>(*_graphicsDevice);
|
||||
|
||||
Game::Initialize();
|
||||
}
|
||||
XnaErrorCode err;
|
||||
texture = Texture2D::FromStream(*_graphicsDevice, "D:\\sprite.jpg", &err);
|
||||
|
||||
void LoadContent() override {
|
||||
spriteBatch = New<SpriteBatch>(*_graphicsDevice);
|
||||
auto audio = AudioEngine();
|
||||
|
||||
XnaErrorCode err;
|
||||
texture = Texture2D::FromStream(*_graphicsDevice, "D:\\sprite.jpg", &err);
|
||||
Game::LoadContent();
|
||||
}
|
||||
|
||||
auto audio = AudioEngine();
|
||||
void Update(GameTime const& gameTime) override {
|
||||
if (Keyboard::GetState().IsKeyDown(Keys::Escape) || GamePad::GetState(PlayerIndex::One).IsButtonDown(Buttons::Back))
|
||||
Exit();
|
||||
|
||||
Game::LoadContent();
|
||||
}
|
||||
oldState = currentState;
|
||||
currentState = Mouse::GetState();
|
||||
const auto rec = Rectangle((graphics->PreferredBackBufferWidth() / 2) - 100, (graphics->PreferredBackBufferHeight() / 2) - 100, 200, 200);
|
||||
|
||||
void Update(GameTime const& gameTime) override {
|
||||
if (currentState.LeftButton == ButtonState::Pressed && oldState.LeftButton == ButtonState::Released) {
|
||||
graphics->ToggleFullScreen();
|
||||
}
|
||||
|
||||
Game::Update(gameTime);
|
||||
}
|
||||
if (currentState.RightButton == ButtonState::Pressed && oldState.RightButton == ButtonState::Released) {
|
||||
position.X += 50;
|
||||
}
|
||||
|
||||
void Draw(GameTime const& gameTime) override {
|
||||
_graphicsDevice->Clear(Colors::CornflowerBlue);
|
||||
Game::Update(gameTime);
|
||||
}
|
||||
|
||||
spriteBatch->Begin();
|
||||
spriteBatch->Draw(*texture, position, nullptr, Colors::White, 0, { 0,0 }, 0.5F, SpriteEffects::None, 0);
|
||||
spriteBatch->End();
|
||||
void Draw(GameTime const& gameTime) override {
|
||||
_graphicsDevice->Clear(Colors::CornflowerBlue);
|
||||
|
||||
Game::Draw(gameTime);
|
||||
}
|
||||
spriteBatch->Begin();
|
||||
spriteBatch->Draw(*texture, position, Colors::White);
|
||||
spriteBatch->End();
|
||||
|
||||
Game::Draw(gameTime);
|
||||
}
|
||||
|
||||
private:
|
||||
PGraphicsDeviceManager graphics = nullptr;
|
||||
PSpriteBatch spriteBatch = nullptr;
|
||||
PTexture2D texture = nullptr; //200x200
|
||||
Vector2 position{};
|
||||
std::vector<Vector2> points;
|
||||
MouseState currentState{};
|
||||
MouseState oldState{};
|
||||
float vel = 1;
|
||||
int var = 0;
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
PGraphicsDeviceManager graphics = nullptr;
|
||||
PSpriteBatch spriteBatch = nullptr;
|
||||
PTexture2D texture = nullptr;
|
||||
Vector2 position{};
|
||||
std::vector<Vector2> points;
|
||||
MouseState currentState{};
|
||||
MouseState oldState{};
|
||||
float vel = 1;
|
||||
};
|
||||
|
||||
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
|
||||
|
||||
auto game = Game1();
|
||||
auto game = xna::Game1();
|
||||
const auto result = game.Run();
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user