La fenêtre SDL que j'ai créé avec un contexte OpenGL a des problèmes:fenêtre SDL OpenGL ne répond pas, transparent
Il est transparent, vous pouvez voir la console derrière elle. Comme vous pouvez le voir dans le code ci-dessous, j'ai juste écrit quelque chose à afficher en rouge à l'écran.
Il ne répond à rien. Dès que je passe la souris sur l'écran, le curseur de chargement apparaît et le clic ne fait rien.
#define main SDL_main
#include "stdafx.h"
int main(int argc, char **argv)
{
bool quit = false;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
SDL_Quit();
return 1;
}
SDL_Window* window = NULL;
window = SDL_CreateWindow("SandVox", 100, 100, 600, 400, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
if (!window) {
std::cout << "Unable to create window" << std::endl;
SDL_DestroyWindow(window);
return 0;
}
SDL_GLContext glcontext = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, glcontext);
glewInit();
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetSwapInterval(1);
SDL_Renderer* render = NULL;
render = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_Event *mainEvent = NULL;
mainEvent = new SDL_Event();
while (!quit && mainEvent->type != SDL_QUIT) ;
{
SDL_PollEvent(mainEvent);
/*
SDL_RenderClear(render);
SDL_RenderPresent(render);
*/
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(window);
}
SDL_GL_DeleteContext(glcontext);
SDL_DestroyRenderer(render);
SDL_DestroyWindow(window);
delete mainEvent;
SDL_Quit();
return 0;
}
stdafx.h n'a rien de très excitant, ceci:
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <GL/glew.h>
#include <GL/GL.h>
#include <GL/glxew.h>
#include <GL/wglew.h>
#include <GL/GLU.h>
EDIT: Pour préempter une question que les gens pourraient avoir, oui, je OpenGL 4.0 installé sur mon ordinateur, j'ai vérifié :)
'SDL_GL_SetAttribute()' ing * après * vous créez un contexte ne fait vraiment rien. – genpfault
Je vous suggère de bien regarder votre déclaration de boucle d'événement 'while'. Il y a un point-virgule ici, ça n'appartient pas. Pro-Astuce: Utilisez un outil comme uncrustify pour formater automatiquement l'indentation de votre code; Je l'ai fait à votre code et en raison du point-virgule superflus, l'accolade d'ouverture "boucles" se termine dans une ligne différente (vous avez besoin de l'indentation de style K & R bien sûr pour voir cela). – datenwolf
datenwolf: Wow, c'était maladroit! Je n'ai pas vu cela :) –