glewInit() Failed, OpenGL App - Stack Overflow

文章推薦指數: 80 %
投票人數:10人

Call glewInit once for each rendering context? or exactly once ... Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore glewInit()Failed,OpenGLApp AskQuestion Asked 9years,5monthsago Modified 2years,4monthsago Viewed 42ktimes 10 3 I'mtryingtobuildanOpenGLAppwithglew/glfw.I'vedownloadedthebinaries,placedthemintherootofmyfolder,addedthepathstotheincludeandlibdirectoriesandtoldmyprojecttorequireglew32.lib,GLFW.libandopengl32.lib. Ievencopiedglew32.libtotherootdirectorybecausemyprojectcouldn'tseeit. ImustkeepallthedependenciesintheprojectdirectorysinceIwillbedistributingthis.I'mataloss. NowwhenIrunmyprogram,itfailsatglewInit() Thisismyimplementationsofar: #include"Common.h" GameEngine::GameEngine() { InitWithSize(1024,768); InitInput(); } voidGameEngine::InitWithSize(int_width,int_height) { try{ //InitialiseGLFW if(!glfwInit()) throwstd::exception("FailedtoinitializeGLFW\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); //OpenawindowandcreateitsOpenGLcontext if(!glfwOpenWindow(_width,_height,0,0,0,0,32,0,GLFW_WINDOW)) throwstd::exception("FailedtoinitializeGLFW\n"); glfwSetWindowTitle("Tutorial01"); //InitializeGLEW if(glewInit()!=GLEW_OK) throwstd::exception("FailedtoinitializeGLEW\n"); }catch(std::system_errorconst&err){ fprintf(stdout,"SystemError:%s",err.what()); glfwTerminate();//Freeglfwifithasbeenallocated //TryAgain this->InitWithSize(_width,_height); }catch(std::exceptionconst&err){ fprintf(stdout,"ExceptionFound:%s",err.what()); }catch(...){ fprintf(stdout,"UnknownExceptionOccurred\n"); } } voidGameEngine::InitInput() { //Ensurewecancapturetheescapekeybeingpressedbelow glfwEnable(GLFW_STICKY_KEYS); } voidGameEngine::StartGameLoop() { do{ //Drawnothing,seeyouintutorial2! //Swapbuffers glfwSwapBuffers(); }//CheckiftheESCkeywaspressedorthewindowwasclosed while(glfwGetKey(GLFW_KEY_ESC)!=GLFW_PRESS&& glfwGetWindowParam(GLFW_OPENED)); } voidGameEngine::InitTestData() { //Anarrayof3vectorswhichrepresents3vertices staticconstGLfloatg_vertex_buffer_data[]={ -1.0f,-1.0f,0.0f, 1.0f,-1.0f,0.0f, 0.0f,1.0f,0.0f, }; } WithmyCommonHeader: #ifndef_COMMON_H #define_COMMON_H //OpenGLLibraries #defineGLEW_STATIC //#pragmacomment(lib,"glew32.lib") #include #include //CoreLibraries #include #include #include #include #include #include //C++11Libraries #include #include #include #include //ManagerClasses #include"ThreadManager.h" #include"GameEngine.h" #include"ShaderManager.h" //LesserClasses #include"Shader.h" #endif openglglew Share Follow editedJul28,2016at11:15 user811773 askedDec9,2012at3:01 JoshEliasJoshElias 3,06077goldbadges3838silverbadges7373bronzebadges 2 Maybeputyourcode?Idon'tseeanyrealerrorsinthatlog,justanotificationthattheprogramfinishedexecuting.YoucanignoreallthePDBsymbolslines. – Tim Dec9,2012at3:24 4 glewInit()actuallyreturnsanerrorcodeyoucanusewithglewGetErrorString.Seeglew.sourceforge.net/basic.html – Grimmy Dec9,2012at6:07 Addacomment  |  5Answers 5 Sortedby: Resettodefault Highestscore(default) Datemodified(newestfirst) Datecreated(oldestfirst) 14 Iknowthisanswercomesabitlate,butIdon'tseeyoumakingtheOpenGLcontextcurrentbycallingglfwMakeContextCurrent(window).YouhavetodothatbeforecallingglewInit() Share Follow editedDec26,2016at16:33 Sid 4,7321414goldbadges5454silverbadges106106bronzebadges answeredDec26,2016at16:10 MaxMax 19711silverbadge77bronzebadges Addacomment  |  7 IfnoerrorisreturnedfromglewInit()itreturns0.Forsomereasonthereturnwasn'tcomparingwelltoGLEW_OKbutifthevalueisanythingbut0,there'sanerror. if(glewInit()){ //HandleError } Share Follow answeredDec9,2012at23:21 JoshEliasJoshElias 3,06077goldbadges3838silverbadges7373bronzebadges Addacomment  |  6 YouareusingCoreOpenGLversion3.3soyoumustspecifyyouareusing"new"andbyGLEWterms"experimental"API.AddthislinebeforecallingglewInit(); glewExperimental=GL_TRUE; Hereisacompleteinitcodefrommyengine.Itisfor4.2butshouldworkthesameforyou: voidEngine::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); #ifdefDEBUG 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("XDEngineV-1.0"); InitGlew(); } voidEngine::InitGlew(){ glewExperimental=GL_TRUE; GLenumerr=glewInit(); if(GLEW_OK!=err) { /*Problem:glewInitfailed,somethingisseriouslywrong.*/ fprintf(stderr,"Error:%s\n",glewGetErrorString(err)); } fprintf(stdout,"Status:UsingGLEW%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); } Share Follow editedJul28,2016at11:27 user811773 answeredDec9,2012at8:25 MichaelIVMichaelIV 10.5k1111goldbadges8282silverbadges209209bronzebadges Addacomment  |  2 Ihadasimilarproblemandfinallygotthesolutiononopengl.org. ItseemsthatGLEWdevelopershaven'tfixedacorecontextproblemyet. Thoughthereisaquiteeasysolution: glewExperimental=TRUE; GLenumerr=glewInit(); if(err!=GLEW_OK) { //Problem:glewInitfailed,somethingisseriouslywrong. cout<



請為這篇文章評分?