Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>All your "different ways" aren't so different. You have to:</p> <ul> <li>create your window (in the usual Win32 way, with <code>RegisterClass(Ex)</code> and <code>CreateWindow(Ex)</code>)</li> <li>create a GDI device context corresponding to your window (<code>GetDC</code>)</li> <li>pick a pixel format which is supported by the display (optional <code>DescribePixelFormat</code>, then <code>ChoosePixelFormat</code>)</li> <li>create your OpenGL context (<code>wglCreateContext</code>)</li> <li>(optional, but required to use GLSL) link OpenGL extension functions (GLee or GLEW helpers, or <code>glGetString(GL_EXTENSIONS)</code> then <code>wglGetProcAddress</code>)</li> <li>(optional) create an OpenGL 3.x context, free the compatibility context (<code>wglCreateContextAttribs</code>)</li> <li>make the context active (<code>wglMakeCurrent</code>)</li> <li>start using OpenGL (set up shader programs, load textures, draw stuff, etc.)</li> </ul> <hr> <p>An excerpt of code showing these steps in action (not suitable for copy+paste, a bunch of RAII wrappers are used):</p> <pre><code>bool Context::attach( HWND hwnd ) { PIXELFORMATDESCRIPTOR pfd = { sizeof(pfd), 1 }; if (!m_dc) { scoped_window_hdc(hwnd).swap(m_dc); pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SUPPORT_COMPOSITION | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; pfd.cAlphaBits = 8; pfd.iLayerType = PFD_MAIN_PLANE; auto format_index = ::ChoosePixelFormat(m_dc.get(), &amp;pfd); if (!format_index) return false; if (!::SetPixelFormat(m_dc.get(), format_index, &amp;pfd)) return false; } auto active_format_index = ::GetPixelFormat(m_dc.get()); if (!active_format_index) return false; if (!::DescribePixelFormat(m_dc.get(), active_format_index, sizeof pfd, &amp;pfd)) return false; if ((pfd.dwFlags &amp; PFD_SUPPORT_OPENGL) != PFD_SUPPORT_OPENGL) return false; m_render_thread = ::CreateThread(NULL, 0, &amp;RenderThreadProc, this, 0, NULL); return m_render_thread != NULL; } DWORD WINAPI Context::RenderThreadProc( LPVOID param ) { Context* const ctx = static_cast&lt;Context*&gt;(param); HDC dc = ctx-&gt;m_dc.get(); SIZE canvas_size; ctx-&gt;m_dc.check_resize(&amp;canvas_size); scoped_hglrc glrc(wglCreateContext(dc)); if (!glrc) return EXIT_FAILURE; if (!glrc.make_current(dc)) return EXIT_FAILURE; if (ctx-&gt;m_major_version &gt; 2 &amp;&amp; GLEE_WGL_ARB_create_context) { int const create_attribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, ctx-&gt;m_major_version, WGL_CONTEXT_MINOR_VERSION_ARB, ctx-&gt;m_minor_version, 0 }; scoped_hglrc advrc(wglCreateContextAttribsARB(dc, 0, create_attribs)); if (advrc) { if (!advrc.make_current(dc)) return EXIT_FAILURE; advrc.swap(glrc); } } { const char* ver = reinterpret_cast&lt;const char*&gt;(glGetString(GL_VERSION)); if (ver) { OutputDebugStringA("GL_VERSION = \""); OutputDebugStringA(ver); OutputDebugStringA("\"\n"); } } glDisable(GL_DITHER); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.f, 0.f, 0.f, 1.f); if (GLEE_WGL_EXT_swap_control) wglSwapIntervalEXT(1); GLuint vao; glGenVertexArrays(1, &amp;vao); glBindVertexArray(vao); while (!::InterlockedExchange(&amp;ctx-&gt;m_stop_render, 0)) { ctx-&gt;process_queued_tasks(); if (ctx-&gt;m_dc.check_resize(&amp;canvas_size)) { glViewport(0, 0, canvas_size.cx, canvas_size.cy); ctx-&gt;process_on_resize(); } glClear(GL_COLOR_BUFFER_BIT); glBindVertexArray(vao); ctx-&gt;process_on_render(); BOOL swapped = ::SwapBuffers(dc); if (!swapped) std::cout &lt;&lt; "::SwapBuffers failure, GetLastError() returns " &lt;&lt; std::hex &lt;&lt; ::GetLastError() &lt;&lt; std::endl; } ctx-&gt;m_program_db.clear(); return EXIT_SUCCESS; } </code></pre> <p>It also doesn't cover window creation, it enables OpenGL on an existing window.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload