PDA

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



PonchoVillegas
08-31-2015, 05:56 PM
// 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

hidefromkgb
08-31-2015, 07:00 PM
Please use the
tag. It does make code (and its errors) easier to read; see below.
Pay attention to the two lines that go after
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
Namely:
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.

PonchoVillegas
08-31-2015, 07:16 PM
Please use the
tag. It does make code (and its errors) easier to read; see below.
Pay attention to the two lines that go after
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
Namely:
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

mgoetschius
09-01-2015, 09:06 AM
You need to add


#include <iostream>