Je suis en train d'écrire un jeu de base en utilisant OpenGL et SDL2 mais chaque fois que je lance le programme de la fenêtre se ferme immédiatementSDL2 OpenGL fenêtre se ferme instantanément
Window.cpp
#include "Window.h"
#include <GL/glew.h>
Window::Window(const char* title)
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 900, 900, SDL_WINDOW_OPENGL);
context = SDL_GL_CreateContext(window);
GLenum status = glewInit();
}
Window::~Window()
{
SDL_DestroyWindow(window);
SDL_GL_DeleteContext(context);
SDL_Quit();
}
void Window::Input()
{
SDL_Event e;
while (true)
{
if (e.type = SDL_QUIT)
{
exit(0);
}
}
}
void Window::Update()
{
SDL_GL_SwapWindow(window);
Input();
}
Window.h
#pragma once
#include <SDL.h>
#include <GL/glew.h>
class Window
{
SDL_Window* window;
SDL_GLContext context;
public:
void Input();
void Update();
Window(const char* title);
~Window();
};
Main.cpp
#include <SDL.h>
#include <GL\glew.h>
#include "Window.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
Window window("Window");
while (true)
{
glClearColor(0, 1, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
window.Update();
}
return 0;
}
Lorsque je cours le code, je reçois un bref éclair d'une fenêtre verte puis il se bloque immédiatement. quand je supprime Input(); à partir de ma fonction de mise à jour, la fenêtre ne plante pas mais elle ne répond pas. Je l'ai essayé de changer SDL_PollEVent à SDL_WaitEvent et en ajoutant des retards à la fonction d'entrée, mais rien ne fonctionne
Merci, il fonctionne maintenant – Abdision
@Abdision: Utilisez [conditions Yoda] (https://fr.wikipedia.org/wiki/Yoda_conditions), vous devriez! – genpfault