Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since it is a console application the two windows will appear which is normal behavior. The first window is the console window that your program creates as it processes main(). The other window is your OpenGL window "FirstWindow"</p> <p>Now for the first problem:</p> <p>include windows header at the top of any header files. </p> <pre><code>#include &lt; windows.h &gt; </code></pre> <p>After that change the main() to the following:</p> <pre><code>int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpComand, int nShow) </code></pre> <p>Then add the following lines:</p> <pre><code>HWND hWnd = GetConsoleWindow(); if(IsWindow(hWnd)) ShowWindow( hWnd, SW_HIDE ); </code></pre> <p>This will hide your console window completely and only FirstWindow will appear. As for your second problem, you must be making a mistake in either of the two function: Init() &amp; Update() Check the code to see where you are making mistake:</p> <p>EDIT: here is your updated code: </p> <p>OpenGL.h</p> <pre><code>#pragma once #pragma comment(lib, "glfw3.lib") #pragma comment(lib, "opengl32.lib") class OpenGL { public: OpenGL(int w, int h); ~OpenGL(); void MainLoop(); private: void Update(); void Prepare(); void Draw(); bool running; int width, height; }; </code></pre> <p>OpenGL.Cpp</p> <pre><code> #include "OpenGL.h" #include &lt;GLFW\glfw3.h&gt; GLFWwindow* windowOne; OpenGL::OpenGL(int w, int h): running(true), width(w), height(h) { glfwInit(); //MER [Sep 20, 2013] Removed teh init() as it made no sense to have sep windowOne = glfwCreateWindow(width,height,"FirstWindow",NULL,NULL); glfwMakeContextCurrent(windowOne); glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); } OpenGL::~OpenGL() { glfwTerminate(); glfwDestroyWindow(windowOne); // MER [Sep 20, 2013] window destruction } void OpenGL::MainLoop() { do { Update(); Prepare(); Draw(); //glFlush(); MER [Sep 20, 2013] No need to call glfwSwapBuffers(windowOne); } while(running); } void OpenGL::Update() { if(glfwGetKey(windowOne, GLFW_KEY_ESCAPE) || !glfwGetWindowAttrib(windowOne, GLFW_FOCUSED)) running = false; } void OpenGL::Prepare() { float ratio=0.0f; //MER [Sep 20, 2013] You need to set the viewport glfwGetFramebufferSize(windowOne, &amp;width, &amp;height); ratio = width / (float) height; glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // MER [Sep 20, 2013] Clear depth buffer too. //MER [Sep 20, 2013] if you don't do this, triangle would be there but not visible. glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f); } void OpenGL::Draw() { glBegin(GL_TRIANGLES); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glEnd(); } </code></pre> <p>Main.Cpp</p> <pre><code>#include &lt;stdlib.h&gt; #include &lt;windows.h&gt; #include "OpenGL.h" int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpComand, int nShow) { HWND hWnd = GetConsoleWindow(); //MER [Sep 20, 2013] This hides the window if(IsWindow(hWnd)) ShowWindow( hWnd, SW_HIDE ); OpenGL* ogl = new OpenGL(200,200); //MER [Sep 20, 2013] sitting in ma office, can't run window in big size ogl-&gt;MainLoop(); delete ogl; return 0; } </code></pre> <p><strong>Glückwünsche, Sie haben Ihre rotierende Dreieck</strong></p> <p>I removed the main.h as it served no purpose. The environment is VS2012 x32bit, Windows 7-32bit. added the additional directory for glfw and openGl32.h (platform sdk 7.1A) linked to gl32.lib (platform SDK 7.1A) and glfw library.</p>
 

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