Opengl context doesn't work outside the main. |
Lolilolight
|
I've frogot to mention it (sorry), my plateform is ubuntu 14.04 64 bits.
|
|||||||||||
|
Re: Opengl context doesn't work outside the main. |
AlexRou
|
Can you create a minimal test program that causes it and upload the source code for that? So like its easier to figure out what went wrong where than to go through your entire source codes.
|
|||||||||||||||
|
Lolilolight
|
Ok, here is a code :
No mean to share the gl context between threads like the SFML library does. :/ But I've switched to SDL because, SDL seems to support more exotic plateforms. SDL fails to get the desktop mode, the function return 0 but the pointer with the current display mode is not affected, here is the code of my the class videomode :
|
|||||||||||||||
|
Lolilolight
|
Here is a more minimal code, it gives me a transparent window :
|
|||||||||||||
|
AlexRou
|
Soo err first of all did you do a SDL_Init()?
Secondly after SDL_Init() and before SDL_CreateWindow and SDL_CreateContex you need to set some GL settings like SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE ); Then to display its SDL_GL_SwapWindow( m_Window ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); Not m_context->Display I think you need to start from scratch with a simple program to just display something so that you learn how to use SDL before you do complicated things. Also it might be a bad idea to include SFML headers in a SDL program incase they mess each other up.
|
|||||||||||||
|
Lolilolight
|
I've done everything that you said but the problem still remains :
|
|||||||||||||
|
AlexRou
|
Your main function must be int main( int argc, char* args[] )
And you must link libSDL2main and libSDL2
|
|||||||||||||||
|
Lolilolight
|
And here with your code, it works when I create the context in the function main but when I want to encapsulate it in a class => nothing.
[code] /*#include "myApplication.h" #include "odfaeg/Graphics/convexShape.h" #include "odfaeg/Graphics/renderWindow.h" #include "glCheck.h" #include <fstream> #include "odfaeg/Network/aes.h" #include "odfaeg/Graphics/3D/cube.h" #include "odfaeg/Graphics/window.h" #include <glew.h> #include <SFML/OpenGL.hpp> #include <functional>*/ #include <SDL2/SDL.h> #include <string> #include <GL/gl.h> #include <iostream> class Window { public : Window (std::string title, int width, int height, int bitsPerPixel, Uint32 style) { SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 ); SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 8 ); SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 ); m_window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, bitsPerPixel); m_context = SDL_GL_CreateContext(m_window); } void close() { SDL_GL_DeleteContext(m_context); SDL_DestroyWindow(m_window); m_window = nullptr; } void display() { SDL_GL_SwapWindow(m_window); } bool isOpen() { return m_window != nullptr; } ~Window() { close(); } private : SDL_Window* m_window; SDL_GLContext m_context; }; int main(void) { if(SDL_Init( SDL_INIT_EVERYTHING ) != 0) { std::cout<<"error"<<std::endl; } Window window("test", 800, 600, 32, SDL_WINDOW_OPENGL); glClearColor(0.f, 0.f, 0.f, 1.f); glViewport( 0, 0, 800, 600 ); /* change to the projection matrix and set our viewing volume. */ glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( 0, 800, 600, 0, -1, 1 ); /* Make sure we're chaning the model view and not the projection */ glMatrixMode( GL_MODELVIEW ); /* Reset The View */ glLoadIdentity(); glPushMatrix(); while (window.isOpen()) { SDL_Event event; while(SDL_PollEvent(&event)) { if (event.window.event == SDL_WINDOWEVENT_CLOSE) { window.close(); } } glMatrixMode( GL_MODELVIEW ); glPopMatrix(); glPushMatrix(); glBegin( GL_TRIANGLE_STRIP ); glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); glVertex3f( -100, -100, 0.0f ); glVertex3f( 100, -100, 0.0f ); glVertex3f( -100, 100, 0.0f ); glVertex3f( 100, 100, 0.0f ); glEnd(); window.display(); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); } SDL_Quit(); return 0; /*MyAppli app(sf::VideoMode(800, 600), "Test odfaeg"); return app.exec();*/ } |
|||||||||||
|
AlexRou
|
There shouldn't be a reason for it to not work in a class unless there is something wrong with the class in the first place.
Try printing SDL_GetError() after every single call to a SDL function. Then after SDL_GL_SwapWindow add this: GLenum error; while( (error = glGetError()) != GL_NO_ERROR ) { char buffer[256]; sprintf( buffer, "\nGL ERROR: %s", gluErrorString( error ) ); cout << buffer; } Then just see if any error pops up. |
|||||||||||
|
Lolilolight
|
I've solved my problem, I gived a wrong parameter. (bitsPerPixels instead of the style)
But it fails to activate a gl3 context : No good framebuffers found. GL 3.x disabled. |
|||||||||||
|
AlexRou
|
Was that message from SDL_GetError or gluErrorString?
Whats your opengl version from glxinfo | grep version And what SDL_GL_SetAttribute are you using?
|
|||||||||||||
|
Lolilolight
|
glxinfo | grep version
server glx version string: 1.4 client glx version string: 1.4 GLX version: 1.4 OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.1.3 OpenGL core profile shading language version string: 3.30 OpenGL version string: 3.0 Mesa 10.1.3 OpenGL shading language version string: 1.30 And for the attributes I use this ones : GL_DEPTH_SIZE, settings.depthBits, GL_STENCIL_SIZE, settings.stencilBits, GL_SAMPLE_BUFFERS, settings.antialiasingLevel > 0, GL_SAMPLES, settings.antialiasingLevel, GL_RED_SIZE, 8, GL_GREEN_SIZE, 8, GL_BLUE_SIZE, 8, GL_ALPHA_SIZE, bitsPerPixel == 32 ? 8 : 0, GL_DOUBLEBUFFER, 1, GL_CONTEXT_MAJOR_VERSION_ARB, static_cast<int>(m_settings.majorVersion), GL_CONTEXT_MINOR_VERSION_ARB, static_cast<int>(m_settings.minorVersion), GL_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB |
|||||||||||
|
Lolilolight
|
I think they are some attribute missing for opengl3..., but, anyway I have another problem with FBOs so..., I think I'll repass on SFML for the moment.
|
|||||||||||
|
AlexRou
|
Try getting things working without the classes first then only add it to the class so its easier to debug, but if you really want to go back to SFML its up to you.
The only attributes you need to care for opengl 3 is GL_CONTEXT_MAJOR_VERSION_ARB GL_CONTEXT_MINOR_VERSION_ARB GL_CONTEXT_PROFILE_MASK_ARB Also try getting it to work with pure SDL incase its one of the other libraries messing up. Referencing your other thread, did you make sure that the texture is properly generated and in GL_RGBA8 format?
|
|||||||||||||
|
AlexRou
|
BTW read up on what triggers the invalid operation error so you know what to look out for. http://oss.sgi.com/projects/ogl-sample/registry/EXT/framebuffer_object.txt (just crtl F invalid_operation)
|
|||||||||||||||
|