Exemple #1
0
void GLWnd::setDoubleBuffered(int db) {
  if (db == m_doublebuffered) return;
  m_doublebuffered = db;
  if (m_rendercontext) {
    glShutdown();
    glInit();
  }
}
Exemple #2
0
int main(int argc, const char * argv[]) {
    
    ModelFactory modelFactory;
    teapot = modelFactory.BuildModel("teapot.obj");

    std::cout << teapot.m_Info.vertCount << std::endl;
    
    if (!glfwInit())
        exit(EXIT_FAILURE);
    
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, GL_VERSION_MAJOR);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GL_VERSION_MINOR);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_SAMPLES, 8);
    
    GLFWwindow* window = glfwCreateWindow(WIN_WIDTH, WIN_HEIGHT, WIN_TITLE, NULL, NULL);
    
    gScreenWidth = WIN_WIDTH;
    gScreenHeight = WIN_HEIGHT;
    
    if (!window) {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);
    
    glInit();
    
    std::cout << glGetString(GL_RENDERER) << std::endl;
    std::cout << glGetString(GL_VERSION) << std::endl;
    
    glfwSetKeyCallback(window, KeyCallback);
    glfwSetWindowSizeCallback(window, ResizeCallback);
    
    while (!glfwWindowShouldClose(window)) {
        glLoop();
        glfwPollEvents();
        glfwSwapBuffers(window);
    }
    
    glShutdown();
    
    glfwDestroyWindow(window);
    
    glfwTerminate();
    return 0;
}
Exemple #3
0
int main(int argc, const char * argv[]) {

    if (!glfwInit())
        exit(EXIT_FAILURE);

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, GL_VERSION_MAJOR);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GL_VERSION_MINOR);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window = glfwCreateWindow(gScreenWidth, gScreenHeight, WIN_TITLE, NULL, NULL);

    if (!window) {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glInit();

    std::cout << glGetString(GL_RENDERER) << std::endl;
    std::cout << glGetString(GL_VERSION) << std::endl;

    glfwSetKeyCallback(window, KeyCallback);
    glfwSetWindowSizeCallback(window, ResizeCallback);
    glfwSetCursorPosCallback(window, CursorPosCallback);

    while (!glfwWindowShouldClose(window)) {
        glLoop();
        glfwPollEvents();
        glfwSwapBuffers(window);
    }

    glShutdown();

    glfwDestroyWindow(window);

    glfwTerminate();
    return 0;
}
Exemple #4
0
void GLWnd::glInit() {
  if (m_rendercontext || m_dc) glShutdown();

  OSWINDOWHANDLE tmpwnd = NULL;
  HDC tmpdc = NULL;

  tmpwnd = StdWnd::createWnd(0, 0, 10, 10, TRUE, 0, NULL, WASABI_API_APP->main_gethInstance(), "WGLDUMMY", wglDummyWndProc, NULL);
  tmpdc = GetDC(tmpwnd);

  PIXELFORMATDESCRIPTOR pfd;
  MEMSET(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
  pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  pfd.nVersion = 1;
  pfd.dwFlags = PFD_SUPPORT_OPENGL|(m_doublebuffered?PFD_DOUBLEBUFFER:0)|PFD_DRAW_TO_WINDOW|PFD_GENERIC_ACCELERATED;
  pfd.iPixelType = PFD_TYPE_RGBA;
  // todo: make this configurable
  pfd.cColorBits = 24;
  pfd.cDepthBits = 16;
  pfd.cAlphaBits = 8;
  pfd.cStencilBits = 16;
  pfd.iLayerType = PFD_MAIN_PLANE;

  HGLRC tmprc;
  int baseformat = ChoosePixelFormat(tmpdc, &pfd);
  if (baseformat == 0 || !SetPixelFormat(tmpdc, baseformat, &pfd) || ((tmprc = wglCreateContext(tmpdc)) == NULL)) {
	  ReleaseDC(tmpwnd, tmpdc);
	  StdWnd::destroyWnd(tmpwnd);
    // could not even create a simple opengl window
    return;
  }
  int reqformat = baseformat;
  if (m_wantmultisampling) {
    wglMakeCurrent(tmpdc, tmprc);
    m_multisampling = 0;
    if (GLeeInit()) {
      if (GLEE_ARB_multisample) {
        int pixelFormat;
        BOOL bStatus;
        UINT numFormats;
        float fAttributes[] = {0,0};
        int iAttributes[] = { WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
	                            WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
	                            WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
	                            WGL_COLOR_BITS_ARB,24,
	                            WGL_ALPHA_BITS_ARB,8,
	                            WGL_DEPTH_BITS_ARB,16,
	                            WGL_STENCIL_BITS_ARB,0,
	                            WGL_DOUBLE_BUFFER_ARB, m_doublebuffered?GL_TRUE:GL_FALSE,
	                            WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
	                            WGL_SAMPLES_ARB,4,
	                            0,0};
    
        bStatus = wglChoosePixelFormatARB(tmpdc,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
        if ((bStatus == GL_TRUE) && (numFormats >= 1)) {
          m_multisampling = 1;
	        reqformat = pixelFormat;
        } else {
          // ok that failed, try using 2 samples now instead of 4
          iAttributes[19] = 2;
          bStatus = wglChoosePixelFormatARB(tmpdc,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
          if ((bStatus == GL_TRUE) && (numFormats >= 1)) {
            m_multisampling = 1;
  	        reqformat = pixelFormat;	  
          }
        }
      }
    }
  }

  wglMakeCurrent(NULL, NULL);
  ReleaseDC(tmpwnd, tmpdc);
  wglDeleteContext(tmprc);
  StdWnd::destroyWnd(tmpwnd);

  m_dc = StdWnd::getDC(gethWnd());

  SetPixelFormat(m_dc, reqformat, &pfd);

  m_rendercontext = wglCreateContext(m_dc);
  wglMakeCurrent(m_dc, m_rendercontext);

  GLeeInit();
  resetWaitVertical();
}
Exemple #5
0
GLWnd::~GLWnd() {
  glShutdown();
}