Example #1
0
OSGLContext_win::OSGLContext_win(const FramebufferConfig& pixelFormatAttrs,
                                 int major,
                                 int minor,
                                 bool coreProfile,
                                 const GLRendererID &rendererID,
                                 const OSGLContext_win* shareContext)
    : _dc(0)
    , _handle(0)
    , _interval(0)
    , _windowHandle(0)
{
    if ( !createWindow(&_windowHandle) ) {
        throw std::runtime_error("WGL: Failed to create window");
    }

    createGLContext(pixelFormatAttrs, major, minor, coreProfile, rendererID, shareContext);

    if ( analyzeContextWGL(pixelFormatAttrs, major, minor) ) {
        // Some window hints require us to re-create the context using WGL
        // extensions retrieved through the current context, as we cannot
        // check for WGL extensions or retrieve WGL entry points before we
        // have a current context (actually until we have implicitly loaded
        // the vendor ICD)

        // Yes, this is strange, and yes, this is the proper way on WGL

        // As Windows only allows you to set the pixel format once for
        // a window, we need to destroy the current window and create a new
        // one to be able to use the new pixel format

        // Technically, it may be possible to keep the old window around if
        // we're just creating an OpenGL 3.0+ context with the same pixel
        // format, but it's not worth the added code complexity

        // First we clear the current context (the one we just created)
        // This is usually done by glfwDestroyWindow, but as we're not doing
        // full GLFW window destruction, it's duplicated here
        makeContextCurrent(NULL);

        // Next destroy the Win32 window and WGL context (without resetting
        // or destroying the GLFW window object)
        destroyContext();
        destroyWindow();

        // ...and then create them again, this time with better APIs
        if ( !createWindow(&_windowHandle) ) {
            throw std::runtime_error("WGL: Failed to create window");
        }

        createGLContext(pixelFormatAttrs, major, minor, coreProfile, rendererID, shareContext);
    }
}
Example #2
0
// create window
Window* Window_Create(unsigned int x, unsigned int y, unsigned int width, unsigned int height, const char* const defaultName)
{
    // initialize application window
    Window* window = malloc(sizeof(Window));
    {
        memset(window, 0, sizeof(Window));
        window->X = x;
        window->Y = y;
        window->Width = width;
        window->Height = height;

        Window_SetTitle(window, defaultName);
    }

    // initialize win32 window struct
    g_win32Window = malloc(sizeof(Win32Window));
    {
        memset(g_win32Window, 0, sizeof(Win32Window));
        g_win32Window->window = window;
    }

    // create win32 window
    createWin32Window(g_win32Window, window);

    // create opengl context
    createGLContext(g_win32Window, window);

    return window;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	createWindow(hInstance);
	createGLContext();
	imguiRenderGLInit("c:\\windows\\fonts\\calibri.ttf");

	timeBeginPeriod(1);

	ShowWindow(hWnd, SW_SHOW);

	for (;;) {
		MSG msg;
		while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
			if (msg.message == WM_QUIT)
				return 0;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		renderFrame();
	}

	timeEndPeriod(1);
}
Example #4
0
int main(int argc, char** argv) {
  fullscreen = false;
  grab = false;
  quit = false;
  initScreen();
  initFrameBuffer();
  createGLContext();
  createColorMap();

  createWindow();
  
  createBlankCursor();
  
  int x = 0;
  
  while(x<5000) {
    renderFrame();
    updateWindowTitle();
    x++;
    }
  
  
      /* Cleanup 
    glXDestroyWindow(display, glxwindow);
    xcb_destroy_window(connection, window);
    glXDestroyContext(display, context);
    XCloseDisplay(display);
      */
  
  return 0;
}
Example #5
0
void SDLOpenGL::init()
{
    if(SDL_Init(SDL_INIT_EVERYTHING) <0)
    {
        errorExit("error calling init");
    }
    m_window=SDL_CreateWindow(m_name.c_str(),m_x,m_y,m_width,m_height,SDL_WINDOW_OPENGL);

    if(!m_window)
    {
        errorExit("Could Not Open Window");
    }
    createGLContext();

}
Example #6
0
void GLRenderWidget::initialize(QWidget *parent)
{
	createGLContext(parent);

	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable( GL_TEXTURE_2D );
	//setuping opengl surface engine
    ASSERT_WITH_CODE(initShaders() == true && initSceneRenderTraget() == true, "Critical error occurred during OpenGL initialization! \r\nProgram will stop in 30 seconds or terminate it manually...", Sleep(30000);exit(1));
    ASSERT_WITH_CODE(MqsOpenGlSurface::initOpenGl(GLContext) == true, "Critical error occurred during OpenGL initialization! \r\nProgram will stop in 30 seconds or terminate it manually...", Sleep(30000);exit(1));

    setMouseTracking(true);

	//setuping timers
	QTimer *fps_timer = new QTimer(this);
	connect(fps_timer, SIGNAL(timeout()), this, SLOT(calcFPS()));
	fps_timer->start(1000);

	QTimer *render_timer = new QTimer(this);
	connect(render_timer, SIGNAL(timeout()), this, SLOT(paintGL()));
    render_timer->start(30);

	connect(this, SIGNAL(initMainScene()), parent, SLOT(initScene()));
	emit initMainScene();

	// create textures for FBO
	glGenTextures(1, &render_rgb_texture_id);
	glGenTextures(1, &render_depth_texture_id);
    glGenFramebuffers(1, &_fboId);
    glGenBuffers(2, _rgb_pbo);
    glGenBuffers(2, _yuv_y_pbo);
    glGenBuffers(2, _yuv_u_pbo);
    glGenBuffers(2, _yuv_v_pbo);

	traceerr("OpenGl render initialized successfully...");
}
Example #7
0
bool Graphics::setOpenGLMode()
{
#ifdef USE_OPENGL
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    if (!(mWindow = graphicsManager.createWindow(
        mActualWidth, mActualHeight,
        mBpp, getOpenGLFlags())))
    {
        logger->log("Window/context creation failed");
        mRect.w = 0;
        mRect.h = 0;
        return false;
    }

#if defined(USE_X11)
    Glx::initFunctions();
#endif
#ifdef USE_SDL2
    int w1 = 0;
    int h1 = 0;
    SDL_GetWindowSize(mWindow, &w1, &h1);
    mRect.w = static_cast<int32_t>(w1 / mScale);
    mRect.h = static_cast<int32_t>(h1 / mScale);

    createGLContext();
#else  // USE_SDL2

    createGLContext();
    mRect.w = static_cast<uint16_t>(mWindow->w / mScale);
    mRect.h = static_cast<uint16_t>(mWindow->h / mScale);

#endif  // USE_SDL2

#ifdef __APPLE__
    if (mSync)
    {
        const GLint VBL = 1;
        CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
    }
#endif

    graphicsManager.setGLVersion();
    graphicsManager.logVersion();

    // Setup OpenGL
    glViewport(0, 0, mActualWidth, mActualHeight);
    int gotDoubleBuffer = 0;
    SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer);
    logger->log("Using OpenGL %s double buffering.",
                (gotDoubleBuffer ? "with" : "without"));

    graphicsManager.initOpenGL();
    initArrays(graphicsManager.getMaxVertices());
    graphicsManager.updateTextureCompressionFormat();
    graphicsManager.updateTextureFormat();
    updateMemoryInfo();

    GLint texSize;
    bool rectTex = graphicsManager.supportExtension(
        "GL_ARB_texture_rectangle");
    if (rectTex
        && OpenGLImageHelper::getInternalTextureType() == 4
        && getOpenGL() != RENDER_GLES_OPENGL
        && getOpenGL() != RENDER_MODERN_OPENGL
        && config.getBoolValue("rectangulartextures")
        && !graphicsManager.isUseTextureSampler())
    {
        logger->log1("using GL_ARB_texture_rectangle");
        OpenGLImageHelper::mTextureType = GL_TEXTURE_RECTANGLE_ARB;
        glEnable(GL_TEXTURE_RECTANGLE_ARB);
        glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
        OpenGLImageHelper::mTextureSize = texSize;
        logger->log("OpenGL texture size: %d pixels (rectangle textures)",
            OpenGLImageHelper::mTextureSize);
    }
    else
    {
        OpenGLImageHelper::mTextureType = GL_TEXTURE_2D;
        glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
        OpenGLImageHelper::mTextureSize = texSize;
        logger->log("OpenGL texture size: %d pixels",
            OpenGLImageHelper::mTextureSize);
    }
    return videoInfo();
#else  // USE_OPENGL

    return false;
#endif  // USE_OPENGL
}