Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Trying to create my first window, running into some errors, take a look at my code?

  1. #1
    Newbie Newbie
    Join Date
    Aug 2015
    Posts
    2

    Trying to create my first window, running into some errors, take a look at my code?

    // GLEW
    #define GLEW_STATIC
    #include <GL/glew.h>
    // GLFW
    #include <GLFW/glfw3.h>
    int main()
    {
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    return 0;
    }
    GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);
    if (window == nullptr)
    {
    std::cout << "Failed to create GLFW window" << std::endl;
    glfwTerminate();
    return -1;
    }
    glfwMakeContextCurrent(window);

    glewExperimental = GL_TRUE;
    if (glewInit() != GLEW_OK)
    {
    std::cout << "Failed to initialize GLEW" << std::endl;
    return -1;
    }
    glViewport(0, 0, 800, 600);
    while (!glfwWindowShouldClose(window))
    {
    glfwPollEvents();
    glfwSwapBuffers(window);
    }
    glfwTerminate();
    return 0;

    The errors I'm getting:
    Severity Code Description Project File Line
    Error (active) expected a declaration win32console c:\Users\Admin\OpenGL\TheBrookyBox\win32console\wi n32console\config.cpp 18
    Error C2059 syntax error: 'if' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 18
    Error C2143 syntax error: missing ';' before '{' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 19
    Error C2447 '{': missing function header (old-style formal list?) win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 19
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 24
    Error C2365 'glfwMakeContextCurrent': redefinition; previous definition was 'function' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 24
    Error C2440 'initializing': cannot convert from 'GLFWwindow *' to 'int' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 24
    Error (active) this declaration has no storage class or type specifier win32console c:\Users\Admin\OpenGL\TheBrookyBox\win32console\wi n32console\config.cpp 26
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 26
    Error C2371 'glewExperimental': redefinition; different basic types win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 26
    Error (active) expected a declaration win32console c:\Users\Admin\OpenGL\TheBrookyBox\win32console\wi n32console\config.cpp 27
    Error C2059 syntax error: 'if' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 27
    Error C2143 syntax error: missing ';' before '{' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 28
    Error C2447 '{': missing function header (old-style formal list?) win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 28
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 32
    Error C2365 'glViewport': redefinition; previous definition was 'function' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 32
    Error C2440 'initializing': cannot convert from 'initializer list' to 'int' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 32
    Error (active) expected a declaration win32console c:\Users\Admin\OpenGL\TheBrookyBox\win32console\wi n32console\config.cpp 33
    Error C2059 syntax error: 'while' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 33
    Error C2143 syntax error: missing ';' before '{' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 34
    Error C2447 '{': missing function header (old-style formal list?) win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 34
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 38
    Error C2556 'int glfwTerminate(void)': overloaded function differs only by return type from 'void glfwTerminate(void)' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 38
    Error C2371 'glfwTerminate': redefinition; different basic types win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 38
    Error (active) expected a declaration win32console c:\Users\Admin\OpenGL\TheBrookyBox\win32console\wi n32console\config.cpp 39
    Error C2059 syntax error: 'return' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 39

  2. #2
    Intern Newbie
    Join Date
    May 2015
    Posts
    37
    1. Please use the [CODE][/CODE] tag. It does make code (and its errors) easier to read; see below.
    2. Pay attention to the two lines that go after
      Code :
      glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
      Namely:
      Code :
      return 0;
      }
      This means you are ending your main() function, so everything that goes below is out of its context.
      Unlike many other programming languages, C/C++ disallows code to be placed outside a function, which seems to be the cause of your errors.
      Remove these two lines, and put a closing curly brace at the very end of your code, and it might work.

  3. #3
    Newbie Newbie
    Join Date
    Aug 2015
    Posts
    2
    Quote Originally Posted by hidefromkgb View Post
    1. Please use the [CODE][/CODE] tag. It does make code (and its errors) easier to read; see below.
    2. Pay attention to the two lines that go after
      Code :
      glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
      Namely:
      Code :
      return 0;
      }
      This means you are ending your main() function, so everything that goes below is out of its context.
      Unlike many other programming languages, C/C++ disallows code to be placed outside a function, which seems to be the cause of your errors.
      Remove these two lines, and put a closing curly brace at the very end of your code, and it might work.

    // GLEW
    #define GLEW_STATIC
    #include <GL/glew.h>
    // GLFW
    #include <GLFW/glfw3.h>
    int main()
    {
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);


    GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);
    if (window == nullptr)
    {
    std::cout << "Failed to create GLFW window" << std::endl;
    glfwTerminate();
    return -1;
    }
    glfwMakeContextCurrent(window);

    glewExperimental = GL_TRUE;
    if (glewInit() != GLEW_OK)
    {
    std::cout << "Failed to initialize GLEW" << std::endl;
    return -1;
    }
    glViewport(0, 0, 800, 600);
    while (!glfwWindowShouldClose(window))

    glfwPollEvents();
    glfwSwapBuffers(window);
    }
    Edited the code


    Now I'm getting these errors:
    Severity Code Description Project File Line
    Error C2039 'cout': is not a member of 'std' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 19
    Error C2065 'cout': undeclared identifier win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 19
    Error C2039 'endl': is not a member of 'std' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 19
    Error C2065 'endl': undeclared identifier win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 19
    Error (active) namespace "std" has no member "cout" win32console c:\Users\Admin\OpenGL\TheBrookyBox\win32console\wi n32console\config.cpp 19
    Error (active) namespace "std" has no member "endl" win32console c:\Users\Admin\OpenGL\TheBrookyBox\win32console\wi n32console\config.cpp 19
    Error C2039 'cout': is not a member of 'std' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 28
    Error C2065 'cout': undeclared identifier win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 28
    Error C2039 'endl': is not a member of 'std' win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 28
    Error C2065 'endl': undeclared identifier win32console c:\users\admin\opengl\thebrookybox\win32console\wi n32console\config.cpp 28
    Error (active) namespace "std" has no member "cout" win32console c:\Users\Admin\OpenGL\TheBrookyBox\win32console\wi n32console\config.cpp 28
    Error (active) namespace "std" has no member "endl" win32console c:\Users\Admin\OpenGL\TheBrookyBox\win32console\wi n32console\config.cpp 28

  4. #4
    Newbie Newbie
    Join Date
    Aug 2015
    Posts
    5
    You need to add

    Code :
    #include <iostream>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •