C++ OpenGL Shaders errors -


#include <stdio.h> #include <stdlib.h> #include <string> #include <fstream>  #include <gl\glew.h> #include <gl\freeglut.h> #include <glfw\glfw3.h>  std::string loadfiletostring(const char* filepath) { std::string filedata; std::ifstream stream(filepath, std::ios::in);  if (stream.is_open()) {     std::string line = "";      while (getline(stream, line))     {         filedata += "\n" + line;      }     stream.close();  } return filedata;  }  gluint loadshaders(const char* vertshaderpath, const char* fragshaderpath) { gluint vertshader = glcreateshader(gl_vertex_shader); gluint fragshader = glcreateshader(gl_fragment_shader);  std::string vertshadersource = loadfiletostring(vertshaderpath); std::string fragshadersource = loadfiletostring(fragshaderpath);  const char* rawvertshadersource = vertshadersource.c_str(); const char* rawfragshadersource = fragshadersource.c_str();  glshadersource(vertshader, 1, &rawvertshadersource, null); glshadersource(fragshader, 1, &rawfragshadersource, null);  glcompileshader(vertshader); glcompileshader(fragshader);  gluint program = glcreateprogram(); glattachshader(program, vertshader); glattachshader(program, fragshader); gllinkprogram(program);  return program;  }    int main() { if (glfwinit() == false) {     fprintf(stderr, "glwf dailed initialise");     return -1; }  //4 aa glfwwindowhint(glfw_samples, 4); glfwwindowhint(glfw_context_version_major, 3); glfwwindowhint(glfw_context_version_minor, 3); glfwwindowhint(glfw_opengl_profile, glfw_opengl_profile);  glfwwindow* window; window = glfwcreatewindow(640, 480, "my opengl", null, null);  if (!window) {     fprintf(stderr, "window failed create");      glfwterminate();     return -1; }  glfwmakecontextcurrent(window); glewexperimental = true;  if (glewinit() != glew_ok) {     fprintf(stderr, "glew failed initialise");     glfwterminate();      return -1;   }  gluint vaoid; glgenvertexarrays(1, &vaoid); glbindvertexarray(vaoid);  static const glfloat verts[] = {     -1.0f, -1.0f, 0.0f,     1.0f, -1.0f, 0.0f,     0.0f, 1.0f, 0.0f  };//end static  gluint program = loadshaders("shader.vertshader", "shader.fragshader");  gluint vboid;  glgenbuffers(1, &vboid); glbindbuffer(gl_array_buffer, vboid); glbufferdata(gl_array_buffer, sizeof(verts), verts, gl_static_draw);  do{     glclear(gl_color_buffer_bit);     glenablevertexattribarray(0);      glbindbuffer(gl_array_buffer, vboid);     glvertexattribpointer(0, 3, gl_float, gl_false, 0, (void*)0);      gluseprogram(program);     gldrawarrays(gl_triangles, 0, 3);      gldisablevertexattribarray(0);      glfwswapbuffers(window);     glfwpollevents();  } while (glfwwindowshouldclose(window) == false);  return 0;  } 

when i run program, "window failed create" on window, while i should triangle guess. me check please?

and "'homework4.exe' (win32): loaded 'c:\users\wanhua\desktop\computer graphic\homework4\homework4\glew32.dll'. module built without symbols. " means???

and output shows below:

'homework4.exe' (win32): loaded 'c:\users\wanhua\desktop\computer graphic\homework4\debug\homework4.exe'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\ntdll.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\kernel32.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\kernelbase.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\users\wanhua\desktop\computer graphic\homework4\homework4\glew32.dll'. module built without symbols. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\user32.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\gdi32.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\shell32.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\msvcp120d.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\opengl32.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\msvcr120d.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\msvcrt.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\combase.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\shlwapi.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\advapi32.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\glu32.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\ddraw.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\rpcrt4.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\sechost.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\dciman32.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\sspicli.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\cryptbase.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\bcryptprimitives.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\imm32.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\msctf.dll'. cannot find or open pdb file. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\uxtheme.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\winmm.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\winmmbase.dll'. symbols     loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\cfgmgr32.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\devobj.dll'. symbols loaded. 'homework4.exe' (win32): loaded 'c:\windows\syswow64\dwmapi.dll'. symbols loaded. 'homework4.exe' (win32): unloaded 'c:\windows\syswow64\winmmbase.dll' 'homework4.exe' (win32): unloaded 'c:\windows\syswow64\devobj.dll' 'homework4.exe' (win32): unloaded 'c:\windows\syswow64\cfgmgr32.dll' 'homework4.exe' (win32): unloaded 'c:\windows\syswow64\winmm.dll' 'homework4.exe' (win32): unloaded 'c:\windows\syswow64\dwmapi.dll' program '[14652] homework4.exe' has exited code -1 (0xffffffff). 

this call looks invalid:

glfwwindowhint(glfw_opengl_profile, glfw_opengl_profile); 

the first parameter fine, you're passing same value second parameter. second parameter specifies which profile want use, valid options are:

  • glfw_opengl_compat_profile: compatibility profile
  • glfw_opengl_core_profile: core profile

so using core profile, correct call is:

glfwwindowhint(glfw_opengl_profile, glfw_opengl_core_profile); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -