Estoy intentando configurar un proyecto OpenGL utilizando GLFW en Visual C++ 2008 (Windows 7). He añadido el GLFW incluir y directorios de la biblioteca al proyecto de incluir y rutas de biblioteca, y yo he puesto lo siguiente en dependencias adicionales:Muchos identificadores no declarados relacionados con OpenGL usando GLFW
GLFW.lib glu32.lib opengl32.lib
Eso es todo lo que tengo que hacer, ¿verdad? Pero cuando trato de compilar cualquier programa OpenGl (excepto uno extremadamente simple que solo borra la pantalla usando glClear) obtengo un montón de identificadores no declarados y errores de identificador no encontrado. ¿Alguna idea de por qué esto puede pasar? Aquí está la lista completa de errores:
1>Compiling...
1>main.cpp
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(9) : error C2146: syntax error : missing ';' before identifier 'VBO'
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(9) : error C2377: 'GLuint' : redefinition; typedef cannot be overloaded with any other symbol
1> c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h(52) : see declaration of 'GLuint'
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(43) : error C3861: 'glEnableVertexAttribArray': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(45) : error C2065: 'GL_ARRAY_BUFFER' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(45) : error C3861: 'glBindBuffer': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(47) : error C3861: 'glVertexAttribPointer': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(55) : error C3861: 'glDisableVertexAttribArray': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(78) : error C3861: 'glGenBuffers': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(80) : error C2065: 'GL_ARRAY_BUFFER' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(80) : error C3861: 'glBindBuffer': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(82) : error C2065: 'GL_ARRAY_BUFFER' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(82) : error C2065: 'GL_STATIC_DRAW' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(82) : error C3861: 'glBufferData': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(87) : error C2146: syntax error : missing ')' before identifier 'ShaderProgram'
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(87) : error C2182: 'AddShader' : illegal use of type 'void'
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(87) : error C2440: 'initializing' : cannot convert from 'Vector3f' to 'int'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(87) : error C2059: syntax error : ')'
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(89) : error C2143: syntax error : missing ';' before '{'
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(89) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(144) : error C2146: syntax error : missing ';' before identifier 'ShaderProgram'
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(144) : error C2065: 'ShaderProgram' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(144) : error C3861: 'glCreateProgram': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(148) : error C2065: 'ShaderProgram' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(158) : error C2065: 'ShaderProgram' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(158) : error C2065: 'GL_VERTEX_SHADER' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(160) : error C2065: 'ShaderProgram' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(160) : error C2065: 'GL_FRAGMENT_SHADER' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2065: 'GLchar' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2146: syntax error : missing ';' before identifier 'ErrorLog'
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2065: 'ErrorLog' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2059: syntax error : '{'
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2143: syntax error : missing ';' before '{'
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(166) : error C2143: syntax error : missing ';' before '}'
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(170) : error C2065: 'ShaderProgram' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(170) : error C3861: 'glLinkProgram': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(172) : error C2065: 'ShaderProgram' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(172) : error C2065: 'GL_LINK_STATUS' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(172) : error C3861: 'glGetProgramiv': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(176) : error C2065: 'ShaderProgram' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(176) : error C2065: 'ErrorLog' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(176) : error C2070: ''unknown-type'': illegal sizeof operand
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(176) : error C2065: 'ErrorLog' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(176) : error C3861: 'glGetProgramInfoLog': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(178) : error C2065: 'ErrorLog' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(186) : error C2065: 'ShaderProgram' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(186) : error C3861: 'glValidateProgram': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(188) : error C2065: 'ShaderProgram' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(188) : error C2065: 'GL_VALIDATE_STATUS' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(188) : error C3861: 'glGetProgramiv': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(192) : error C2065: 'ShaderProgram' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(192) : error C2065: 'ErrorLog' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(192) : error C2070: ''unknown-type'': illegal sizeof operand
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(192) : error C2065: 'ErrorLog' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(192) : error C3861: 'glGetProgramInfoLog': identifier not found
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(194) : error C2065: 'ErrorLog' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(202) : error C2065: 'ShaderProgram' : undeclared identifier
1>c:\glfw-2.7.3\opengl ikasi\main.cpp(202) : error C3861: 'glUseProgram': identifier not found
EDIT: aquí está todo el programa
#include <stdio.h>
#include <string.h>
#include <GL/glfw.h>
#include "math_3d.h"
GLuint VBO;
static const char* pVS = " \n\
#version 150 \n\
\n\
layout (location = 0) in vec3 Position; \n\
\n\
void main() \n\
{ \n\
gl_Position = vec4(0.5 * Position.x, 0.5 * Position.y, Position.z, 1.0); \n\
}";
static const char* pFS = " \n\
#version 150 \n\
\n\
out vec4 FragColor; \n\
\n\
void main() \n\
{ \n\
FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n\
}";
static void RenderSceneCB()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glfwSwapBuffers();
}
static void CreateVertexBuffer()
{
Vector3f Vertices[3];
Vertices[0] = Vector3f(-1.0f, -1.0f, 0.0f);
Vertices[1] = Vector3f(1.0f, -1.0f, 0.0f);
Vertices[2] = Vector3f(0.0f, 1.0f, 0.0f);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
}
static void AddShader(GLuint ShaderProgram, const char* pShaderText, GLenum ShaderType)
{
GLuint ShaderObj = glCreateShader(ShaderType);
if (ShaderObj == 0) {
fprintf(stderr, "Error creating shader type %d\n", ShaderType);
return ;
}
const GLchar* p[1];
p[0] = pShaderText;
GLint Lengths[1];
Lengths[0]= strlen(pShaderText);
glShaderSource(ShaderObj, 1, p, Lengths);
glCompileShader(ShaderObj);
GLint success;
glGetShaderiv(ShaderObj, GL_COMPILE_STATUS, &success);
if (!success) {
GLchar InfoLog[1024];
glGetShaderInfoLog(ShaderObj, 1024, NULL, InfoLog);
fprintf(stderr, "Error compiling shader type %d: '%s'\n", ShaderType, InfoLog);
return;
}
glAttachShader(ShaderProgram, ShaderObj);
}
static void CompileShaders()
{
GLuint ShaderProgram = glCreateProgram();
if (ShaderProgram == 0) {
fprintf(stderr, "Error creating shader program\n");
return;
}
AddShader(ShaderProgram, pVS, GL_VERTEX_SHADER);
AddShader(ShaderProgram, pFS, GL_FRAGMENT_SHADER);
GLint Success = 0;
GLchar ErrorLog[1024] = { 0 };
glLinkProgram(ShaderProgram);
glGetProgramiv(ShaderProgram, GL_LINK_STATUS, &Success);
if (Success == 0) {
glGetProgramInfoLog(ShaderProgram, sizeof(ErrorLog), NULL, ErrorLog);
fprintf(stderr, "Error linking shader program: '%s'\n", ErrorLog);
return;
}
glValidateProgram(ShaderProgram);
glGetProgramiv(ShaderProgram, GL_VALIDATE_STATUS, &Success);
if (!Success) {
glGetProgramInfoLog(ShaderProgram, sizeof(ErrorLog), NULL, ErrorLog);
fprintf(stderr, "Invalid shader program: '%s'\n", ErrorLog);
return;
}
glUseProgram(ShaderProgram);
}
int main(int argc, char** argv)
{
glfwInit();
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindow(600, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
CreateVertexBuffer();
CompileShaders();
while (1)
{
RenderSceneCB();
}
return 0;
}
EDIT 2: Y aquí la cabecera math_3d.h
#ifndef MATH_3D_H
#define MATH_3D_H
struct Vector3f
{
float x;
float y;
float z;
Vector3f()
{
}
Vector3f(float _x, float _y, float _z)
{
x = _x;
y = _y;
z = _z;
}
};
#endif
La primera línea es un error de sintaxis que muy bien podría arruinar declaraciones 'include' después de ella. Arregle eso primero y vea qué pasa. También sería bueno si incluyó al menos la primera parte de su programa que contiene estas líneas. – HonkyTonk
¡Te ayuda! el primer error corresponde a esta línea: 'GLuint VBO;', así que creo que no es realmente un error sintax, sino un error causado porque no sabe qué es GLuint. Actualizaré la pregunta con la primera parte del programa. – XaitormanX
¿Qué hay escondido dentro de 'math_3d.h'? Tal vez algo allí está mal formado? El compilador encuentra el tipo 'GLuint' y lee los errores con cuidado. – HonkyTonk