2012-12-09 16 views
6

Sto provando a creare un'app OpenGL con glew/glfw. Ho scaricato i file binari, li ho inseriti nella radice della mia cartella, aggiunto i percorsi alle directory di inclusione e lib e ho detto al mio progetto di richiedere glew32.lib, GLFW.lib e opengl32.lib.glewInit() non riuscito, OpenGL App

Ho persino copiato glew32.lib nella directory radice perché il mio progetto non poteva vederlo.

Devo mantenere tutte le dipendenze nella directory del progetto poiché lo distribuirò. Sono in perdita.

Ora, quando eseguo il mio programma, non riesce a glewInit()

Questa è la mia implementazione finora:

#include "Common.h" 

GameEngine::GameEngine() 
{ 
    InitWithSize(1024, 768); 
    InitInput(); 
} 

void GameEngine::InitWithSize(int _width, int _height) 
{ 
    try { 
     // Initialise GLFW 
     if(!glfwInit()) 
      throw std::exception("Failed to initialize GLFW\n"); 

     //glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); 
     glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); 
     glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); 
     glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 

     // Open a window and create its OpenGL context 
     if(!glfwOpenWindow(_width, _height, 0,0,0,0, 32,0, GLFW_WINDOW)) 
      throw std::exception("Failed to initialize GLFW\n"); 


     glfwSetWindowTitle("Tutorial 01"); 

     // Initialize GLEW 
     if (glewInit() != GLEW_OK) 
      throw std::exception("Failed to initialize GLEW\n"); 


    } catch (std::system_error const& err) { 
     fprintf(stdout, "System Error: %s", err.what()); 
     glfwTerminate(); // Free glfw if it has been allocated 
     // Try Again 
     this->InitWithSize(_width, _height); 
    } catch(std::exception const& err) { 
     fprintf(stdout, "Exception Found: %s", err.what()); 
    } catch (...) { 
     fprintf(stdout,"Unknown Exception Occurred\n"); 
    } 
} 

void GameEngine::InitInput() 
{ 
     // Ensure we can capture the escape key being pressed below 
     glfwEnable(GLFW_STICKY_KEYS); 
} 

void GameEngine::StartGameLoop() 
{ 
    do{ 
      // Draw nothing, see you in tutorial 2 ! 

      // Swap buffers 
      glfwSwapBuffers(); 

     } // Check if the ESC key was pressed or the window was closed 
     while(glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS && 
      glfwGetWindowParam(GLFW_OPENED)); 
} 


void GameEngine::InitTestData() 
{ 
    // An array of 3 vectors which represents 3 vertices 
    static const GLfloat g_vertex_buffer_data[] = { 
     -1.0f, -1.0f, 0.0f, 
     1.0f, -1.0f, 0.0f, 
     0.0f, 1.0f, 0.0f, 
    }; 

} 

Con la mia intestazione Comune:

#ifndef _COMMON_H 
#define _COMMON_H 

// OpenGL Libraries 
#define GLEW_STATIC 
//#pragma comment(lib, "glew32.lib") 
#include <GL\glew.h> 
#include <GL\glfw.h> 

// Core Libraries 
#include <Windows.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <map> 
#include <string> 
#include <fstream> 

// C++ 11 Libraries 
#include <memory> 
#include <exception> 
#include <thread> 
#include <chrono> 

// Manager Classes 
#include "ThreadManager.h" 
#include "GameEngine.h" 
#include "ShaderManager.h" 

// Lesser Classes 
#include "Shader.h" 

#endif 
+0

Forse hai messo il tuo codice? Non vedo errori reali in quel registro, solo una notifica che il programma ha terminato l'esecuzione. È possibile ignorare tutte le linee dei simboli PDB. – Tim

+3

'glewInit()' restituisce effettivamente un codice di errore che è possibile utilizzare con 'glewGetErrorString'. Vedi http://glew.sourceforge.net/basic.html – Grimmy

risposta

5

Se nessun errore viene restituito da glewInit() restituisce 0. Per un motivo per cui il rendimento non è stato paragonato bene a GLEW_OK ma se il valore è tutto tranne 0, c'è un errore.

if(glewInit()) { 

    //Handle Error 

} 
3

Si utilizza Core OpenGL versione 3.3, quindi è necessario specificare che si sta utilizzando "nuovo" e l'API "experimental" dei termini GLEW. Aggiungi questa linea prima di chiamare glewInit();

glewExperimental=GL_TRUE; 

Ecco un codice di inizializzazione completo dal mio motore .E 'per 4.2, ma dovrebbe funzionare lo stesso per voi:

void Engine::InitWithGLFW(){ 
    if(!glfwInit()){ 
     exit(EXIT_FAILURE); 
    } 
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4); 
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); 
    //glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT,GL_TRUE); 
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); 
    glfwOpenWindowHint(GLFW_FSAA_SAMPLES,4); 
    glfwDisable(GLFW_AUTO_POLL_EVENTS); 

#ifdef DEBUG 
    glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); 
#endif 

    if(!glfwOpenWindow(_width,_height,8, 8, 8, 8, 24, 8,GLFW_WINDOW)){ 
     glfwTerminate(); 
     exit(EXIT_FAILURE); 
    } 

    glfwSetWindowTitle("XDEngine V-1.0"); 
    InitGlew(); 
} 

void Engine::InitGlew(){ 
    glewExperimental=GL_TRUE; 
    GLenum err = glewInit(); 

    if (GLEW_OK != err) 
    { 
     /* Problem: glewInit failed, something is seriously wrong. */ 
     fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); 

    } 

    fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); 
    glEnable (GL_BLEND); 
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 

    glEnable(GL_MULTISAMPLE); 
    glEnable(GL_DEPTH_CLAMP); 
    glEnable(GL_CULL_FACE); 
    glCullFace(GL_BACK); 

    glfwSetWindowSizeCallback(Reshape); 
} 
1

Ho avuto un problema simile e finalmente ho trovato la soluzione su opengl.org. Sembra che gli sviluppatori di GLEW non abbiano ancora risolto un problema di contesto principale. Anche se c'è una soluzione molto semplice:

glewExperimental=TRUE; 
    GLenum err=glewInit(); 
    if(err!=GLEW_OK) 
    { 
    //Problem: glewInit failed, something is seriously wrong. 
    cout<<"glewInit failed, aborting."<<endl; 
    } 

HTH

5

So che questa risposta arriva un po 'tardi, ma non vedo voi che fate l'attuale contesto OpenGL chiamando glfwMakeContextCurrent(window). Devi farlo prima di chiamare glewInit()

Problemi correlati