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->_index = 0;
|
||||||
adp->_adapter = pAdapter;
|
adp->_adapter = pAdapter;
|
||||||
|
|
||||||
return std::move(adp);
|
return adp;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFactory->Release();
|
pFactory->Release();
|
||||||
@ -239,5 +239,15 @@ namespace xna {
|
|||||||
collection->_displayModes = displayList;
|
collection->_displayModes = displayList;
|
||||||
|
|
||||||
return std::move(collection);
|
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 SubSystemId() const override;
|
||||||
virtual Uint VendorId() const override;
|
virtual Uint VendorId() const override;
|
||||||
virtual UDisplayModeCollection SupportedDisplayModes() 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:
|
public:
|
||||||
IDXGIAdapter1* _adapter{ nullptr };
|
IDXGIAdapter1* _adapter{ nullptr };
|
||||||
|
@ -75,16 +75,16 @@ namespace xna {
|
|||||||
ID3D11DeviceContext* _context{ nullptr };
|
ID3D11DeviceContext* _context{ nullptr };
|
||||||
IDXGIFactory1* _factory = nullptr;
|
IDXGIFactory1* _factory = nullptr;
|
||||||
PSwapChain _swapChain{ nullptr };
|
PSwapChain _swapChain{ nullptr };
|
||||||
|
PGraphicsAdapter _adapter{ nullptr };
|
||||||
|
PRenderTarget2D _renderTarget2D{ nullptr };
|
||||||
|
PBlendState _blendState{ nullptr };
|
||||||
|
xna::Viewport _viewport{};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int _createDeviceFlags{ 0 };
|
unsigned int _createDeviceFlags{ 0 };
|
||||||
D3D_FEATURE_LEVEL _featureLevel{ D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0 };
|
D3D_FEATURE_LEVEL _featureLevel{ D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0 };
|
||||||
float _backgroundColor[4] = { 0, 0, 0, 0 };
|
float _backgroundColor[4] = { 0, 0, 0, 0 };
|
||||||
xna::PresentationParameters _presentParameters;
|
xna::PresentationParameters _presentParameters;
|
||||||
PGraphicsAdapter _adapter{ nullptr };
|
|
||||||
PRenderTarget2D _renderTarget2D{ nullptr };
|
|
||||||
xna::Viewport _viewport{};
|
|
||||||
PBlendState _blendState{ nullptr };
|
|
||||||
bool _usevsync{ true };
|
bool _usevsync{ true };
|
||||||
|
|
||||||
bool createDevice();
|
bool createDevice();
|
||||||
|
@ -33,7 +33,12 @@ namespace xna {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Game::Run() {
|
void Game::Exit()
|
||||||
|
{
|
||||||
|
_gameWindow->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Game::Run() {
|
||||||
Initialize();
|
Initialize();
|
||||||
|
|
||||||
if (_graphicsDevice == nullptr) {
|
if (_graphicsDevice == nullptr) {
|
||||||
|
@ -15,7 +15,8 @@ namespace xna {
|
|||||||
virtual ~Game() override {
|
virtual ~Game() override {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Exit() override{}
|
virtual void Exit() override;
|
||||||
|
|
||||||
virtual int Run() override;
|
virtual int Run() override;
|
||||||
|
|
||||||
virtual PGameWindow Window() override {
|
virtual PGameWindow Window() override {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "game-dx.hpp"
|
#include "game-dx.hpp"
|
||||||
#include "window-dx.hpp"
|
#include "window-dx.hpp"
|
||||||
#include "gdeviceinfo-dx.hpp"
|
#include "gdeviceinfo-dx.hpp"
|
||||||
|
#include "adapter-dx.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
GraphicsDeviceManager::GraphicsDeviceManager(Game*& game) : _game(game) {
|
GraphicsDeviceManager::GraphicsDeviceManager(Game*& game) : _game(game) {
|
||||||
@ -29,23 +30,31 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsDeviceManager::ApplyChanges() {
|
void GraphicsDeviceManager::ApplyChanges() {
|
||||||
//_game->_graphicsDevice = _device;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsDeviceManager::ToggleFullScreen() {
|
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) {
|
void GraphicsDeviceManager::CreateDevice(GraphicsDeviceInformation const& info) {
|
||||||
_device = New<GraphicsDevice>(info);
|
_device = New<GraphicsDevice>(info);
|
||||||
//auto window = _game->Window();
|
_device->Adapter(info.Adapter());
|
||||||
auto window = info.Window();
|
auto window = info.Window();
|
||||||
|
|
||||||
|
window->Size(_backBufferWidth, _backBufferHeight);
|
||||||
|
|
||||||
if (!window->Create()) {
|
if (!window->Create()) {
|
||||||
MessageBox(nullptr, "Falha na criação da janela", "Xna Game Engine", MB_OK);
|
MessageBox(nullptr, "Falha na criação da janela", "Xna Game Engine", MB_OK);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//_device->Initialize(*window);
|
|
||||||
if (!_device->Initialize(*window)) {
|
if (!_device->Initialize(*window)) {
|
||||||
MessageBox(nullptr, "Falha na inicialização do dispositivo gráfico", "Xna Game Engine", MB_OK);
|
MessageBox(nullptr, "Falha na inicialização do dispositivo gráfico", "Xna Game Engine", MB_OK);
|
||||||
return;
|
return;
|
||||||
|
@ -37,14 +37,14 @@ namespace xna {
|
|||||||
virtual void ChangeDevice() override;
|
virtual void ChangeDevice() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr int DefaultBackBufferWidth = 1280;//800;
|
static constexpr int DefaultBackBufferWidth = 800;//800;
|
||||||
static constexpr int DefaultBackBufferHeight = 720;// 480;
|
static constexpr int DefaultBackBufferHeight = 480;// 480;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Game*& _game;
|
Game* _game;
|
||||||
Int _backBufferWidth{ DefaultBackBufferWidth };
|
Int _backBufferWidth{ DefaultBackBufferWidth };
|
||||||
Int _backBufferHeight{ DefaultBackBufferHeight };
|
Int _backBufferHeight{ DefaultBackBufferHeight };
|
||||||
bool _isDeviceDirty{ false };
|
bool _isDeviceDirty{ false };
|
||||||
PGraphicsDevice _device;
|
PGraphicsDevice _device;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -11,60 +11,78 @@ using namespace xna;
|
|||||||
// cout << "Hello CMake." << endl;
|
// cout << "Hello CMake." << endl;
|
||||||
// return 0;
|
// 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 {
|
void Initialize() override {
|
||||||
public:
|
graphics->Initialize();
|
||||||
Game1() {
|
Game::Initialize();
|
||||||
auto _game = reinterpret_cast<Game*>(this);
|
}
|
||||||
graphics = New<GraphicsDeviceManager>(_game);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Initialize() override {
|
void LoadContent() override {
|
||||||
graphics->Initialize();
|
spriteBatch = New<SpriteBatch>(*_graphicsDevice);
|
||||||
|
|
||||||
Game::Initialize();
|
XnaErrorCode err;
|
||||||
}
|
texture = Texture2D::FromStream(*_graphicsDevice, "D:\\sprite.jpg", &err);
|
||||||
|
|
||||||
void LoadContent() override {
|
auto audio = AudioEngine();
|
||||||
spriteBatch = New<SpriteBatch>(*_graphicsDevice);
|
|
||||||
|
|
||||||
XnaErrorCode err;
|
Game::LoadContent();
|
||||||
texture = Texture2D::FromStream(*_graphicsDevice, "D:\\sprite.jpg", &err);
|
}
|
||||||
|
|
||||||
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 {
|
Game::Update(gameTime);
|
||||||
_graphicsDevice->Clear(Colors::CornflowerBlue);
|
}
|
||||||
|
|
||||||
spriteBatch->Begin();
|
void Draw(GameTime const& gameTime) override {
|
||||||
spriteBatch->Draw(*texture, position, nullptr, Colors::White, 0, { 0,0 }, 0.5F, SpriteEffects::None, 0);
|
_graphicsDevice->Clear(Colors::CornflowerBlue);
|
||||||
spriteBatch->End();
|
|
||||||
|
|
||||||
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) {
|
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();
|
const auto result = game.Run();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user