C++ OpenGL Shaders errors - opengl

#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 to 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 to create");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = true;
if (glewInit() != GLEW_OK)
{
fprintf(stderr, "GLEW failed to 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 this program, I always get "Window failed to create" on the window, while I should get a triangle I guess. could anyone help me check please?
and what is "'homework4.exe' (Win32): Loaded 'C:\Users\Wanhua\Desktop\Computer graphic\homework4\homework4\glew32.dll'. Module was built without symbols. " this means???
and that 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 was 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 the 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'
The program '[14652] homework4.exe' has exited with code -1 (0xffffffff).

This call looks invalid:
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_PROFILE);
The first parameter is fine, but you're passing the same value for the second parameter. The second parameter specifies which profile you want to use, where the valid options are:
GLFW_OPENGL_COMPAT_PROFILE: compatibility profile
GLFW_OPENGL_CORE_PROFILE: core profile
So for using the core profile, the correct call is:
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

Related

Program crashes on accessing SSBO in shader

Whenever I try to access an SSBO, I get an error, saying atio6axx.pdb not loaded.
My graphics card (AMD) drivers are updated, but funnily enough while searching for a solution I found this thread, which was posted only a few hours ago, so could this be a driver issue? I searched my PC and found the .dll but not the .pdb, could this be the issue? I've got VS set to loading symbols from Microsoft Symbol Servers but not NuGet.org Symbol Servers.
Relevant code:
Shader (simplified to only show necessary code):
#version 430 core
layout(binding = 5, std430) buffer test
{
float t[];
};
out vec4 colour;
void main()
{
colour = vec4(test.t[0], test.t[1], test.t[2], 1);
}
Creating the SSBO:
float test[3] { 0, 10, 0 };
glGenBuffers(1, &ss_id);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ss_id);
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(float) * 3, test, GL_STATIC_READ);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, ss_id);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
Any help is appreciated
For anyone else having this issue, I found out why it was happening. I was referring to the data in the SSBO with test.t[0], when instead it should have been just t[0].

OpenGL 4.1 on OSX Xcode 6 setup difficulties

I'm trying to learn some OpenGL and immediately found out versions of OpenGL >3.2 were the more relevant ones to learn.
So I've set up my Mac OS X 10.10.3 with Xcode and command line tools to get some examples going.
But jebus this thing is being a pain in the butt.
The error I'm getting is.
Undefined symbols for architecture x86_64:
"LoadShaders(char const*, char const*)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So I have the most recent version of GLFW GLEW cmake to get things going.
I add my header and library paths to the project.
Library Search Paths
/opt/X11/lib /usr/lib/ /Users/mac/Dev/workspace/C++/Test/glfw/build/src/Debug /Users/mac/Dev/workspace/C++/Test/glew/lib
I add the last two directories just to double up on the directory
Header Search Path look similar with include instead of lib
my linkers are vast (from trying random things)
-framework OpenGl -lGLUT -lglew -lglfw -lGL -lGLU -lXmu -lXi -lXext -lX11 -lXt
and I've linked the Binaries with the Libraries as well. Where am I going wrong??
my GPU is the Intel HD 4000 and appears to support up to OpenGL4.1.
Do I need to add compiler flags? Is this just not plausible?
Here's the tutorial code that I'm trying to run.
#include <stdio.h>
#include <stdlib.h>
//GLEW
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLUT/glut.h>
//GLFW
#include <GLFW/glfw3.h>
#include <AGL/glm.h>
GLFWwindow* window;
//no real explanation of what this is.....
#include <common/shader.hpp>
//MAIN FUNCTION
int main(int argc, char *argv[])
{
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
return -1;
}
// specify GL information
glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); // We want 4.1>= OpenGL_version >=3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL
// Open a window and create its OpenGL context
window = glfwCreateWindow( 600, 375, "Tutorial 02", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
// Initialize GLEW
glewExperimental=true; // Needed in core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
// Ensure we can capture the escape key being pressed below
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
// Dark blue background
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
// Create Vertex Array Object.
GLuint VertexArrayID;
glGenVertexArrays(1, &VertexArrayID);
glBindVertexArray(VertexArrayID);
// Create and compile our GLSL program from the shaders
GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" );
// An array of 3 vectors which represents 3 vertices
static const GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
GLuint vertexbuffer;
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
do{
// Clear the screen
glClear( GL_COLOR_BUFFER_BIT );
// Use our Shader
glUseProgram(programID);
// 1st attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
// glVertexAttribPointer(
// Atrribute,
// size,
// type,
// normalized,
// stride,
// array buffer offset
// );
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
// Draw the triangle
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
// Swap buffers
glfwSwapBuffers(window);
glfwPollEvents();
} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0 );
// Cleanup VBO
glDeleteBuffers(1, &vertexbuffer);
glDeleteVertexArrays(1, &VertexArrayID);
glDeleteProgram(programID);
// Close OpenGL window and terminate GLFW
glfwTerminate();
return 0;
}
I mostly followed this guideline here
Oscar Chavez, Setup instructions
The function LoadShaders() is not part of OpenGL, and it is not part of any of the libraries you are using (I see GLEW and GLFW). In short, LoadShaders() is missing.
My guess is that LoadShaders() is a function that the author of the tutorial wrote, but the formatting for the tutorial is a bit frustrating (to say the least!) so I'm not sure.
//no real explanation of what this is.....
#include <common/shader.hpp>
Probably something the author of that tutorial wrote himself and simply dumped into the project sources, without telling anything more. The most annoying part about this lines is the use of wedge brackets (<…>) instead of quotes ("…") because this misleadingly suggests that the header is part of the system libraries and not something local to the project. Somwehere there likely is a common/shader.cpp and therein will probably be a function LoadShaders. It is this very function, that is something completely custom, not something part of OpenGL or any of the helper libraries, which your linker is telling you to be amiss.

Compiling error lnk 2019 under visual studio

I do not know what to with this error. I searched for some solutions, but nothing helps.
Linker Error:
"error LNK2019: unresolved external symbol __ imp__glDrawArrays"
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <GL\glew.h>
#include <GLFW\glfw3.h>
int main()
{
if(glfwInit()==false){
//Did not succeed
fprintf(stderr, "GLFW faild ");
return -1;
}
glfwWindowHint(GLFW_SAMPLES,4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window;
window = glfwCreateWindow(640,480,"Hallo Welt",NULL,NULL);
if(!window)
{
fprintf(stderr, "Window failed");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = true;
if(glewInit() != GLEW_OK)
{
fprintf(stderr, "glew init failed");
glfwTerminate();
return -1;
}
GLuint vaoID; //Vertex array erzeugt
glGenVertexArrays(1, &vaoID);
glBindVertexArray(vaoID); // wir verwenden das VA
static const GLfloat verts[] = {
-1.0f,-1.0f,0.0f,
1.0f,-1.0f,0.0f,
0.0f,1.0f,0.0f};
//Generate VBO
GLuint vboID;
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER,vboID);
glBufferData(GL_ARRAY_BUFFER,sizeof(verts),verts,GL_STATIC_DRAW);
do{
glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER,vboID);
glVertexAttribPointer(0, 3,GL_FLOAT,GL_FALSE,0,(void*)0);
glDrawArrays(GL_TRIANGLES,0,3);
glDisableVertexAttribArray(0);
glfwSwapBuffers(window);
glfwPollEvents();
} while(glfwWindowShouldClose(window)==false);
return 0;
}
I set my directories for my include and lib files.
Under Linker->Input i have glew32.lib, glew32s.lib, glfw3dll.lib
If I delete the function glDrawArrays the code works and i get the black window. But I want to draw a white triangle in the window.
You have a couple of problems here:
You are linking to glew32.lib (dynamic --> DLL) and glew32s.lib (static)
Pick only one, and I would suggest glew32s.lib - but make sure you add GLEW_STATIC to pre-processor definitions when you use glew32s.lib.
You are only linking to support libraries, not the actual OpenGL run-time that ships with Windows
Fix this by adding OpenGL32.lib to your libraries.

Unhandled exception at 0x00000000 in Engine.exe: 0xC0000005: Access violation

I try to build this Tutorial: this one
with the following code in window.cpp:
// Include standard headers
#include <stdio.h>
#include <stdlib.h>
// Include GLEW
#include <GL/glew.h>
// Include GLFW
#include <GL/glfw.h>
//Include GLM
#include <glm/glm.hpp>
using namespace glm;
#include <common/shader.hpp>
int main( void )
{
// Initialise GLFW
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
return -1;
}
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);
// Open a window and create its OpenGL context
if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
{
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
glfwTerminate();
return -1;
}
// Initialize GLEW
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
glfwSetWindowTitle( "Tutorial 02" );
// Ensure we can capture the escape key being pressed below
glfwEnable( GLFW_STICKY_KEYS );
// Dark blue background
glClearColor(0.0f, 0.0f, 0.3f, 0.0f);
GLuint VertexArrayID;
glGenVertexArrays(1, &VertexArrayID);
glBindVertexArray(VertexArrayID);
// Create and compile our GLSL program from the shaders
GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" );
static const GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
GLuint vertexbuffer;
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
do{
// Clear the screen
glClear( GL_COLOR_BUFFER_BIT );
// Use our shader
glUseProgram(programID);
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// Draw the triangle !
glDrawArrays(GL_TRIANGLES, 0, 3); // From index 0 to 3 -> 1 triangle
glDisableVertexAttribArray(0);
// Swap buffers
glfwSwapBuffers();
} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
glfwGetWindowParam( GLFW_OPENED ) );
// Close OpenGL window and terminate GLFW
glfwTerminate();
// Cleanup VBO
glDeleteBuffers(1, &vertexbuffer);
glDeleteVertexArrays(1, &VertexArrayID);
return 0;
}
`
And the following code in the shader.cpp
#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#include <stdlib.h>
#include <string.h>
#include <GL/glew.h>
#include "shader.hpp"
GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){
// Create the shaders
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
// Read the Vertex Shader code from the file
std::string VertexShaderCode;
std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
if(VertexShaderStream.is_open()){
std::string Line = "";
while(getline(VertexShaderStream, Line))
VertexShaderCode += "\n" + Line;
VertexShaderStream.close();
}
// Read the Fragment Shader code from the file
std::string FragmentShaderCode;
std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
if(FragmentShaderStream.is_open()){
std::string Line = "";
while(getline(FragmentShaderStream, Line))
FragmentShaderCode += "\n" + Line;
FragmentShaderStream.close();
}
GLint Result = GL_FALSE;
int InfoLogLength;
// Compile Vertex Shader
printf("Compiling shader : %s\n", vertex_file_path);
char const * VertexSourcePointer = VertexShaderCode.c_str();
glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
glCompileShader(VertexShaderID);
// Check Vertex Shader
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<char> VertexShaderErrorMessage(InfoLogLength);
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL,
&VertexShaderErrorMessage[0]);
fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);
// Compile Fragment Shader
printf("Compiling shader : %s\n", fragment_file_path);
char const * FragmentSourcePointer = FragmentShaderCode.c_str();
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
glCompileShader(FragmentShaderID);
// Check Fragment Shader
glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<char> FragmentShaderErrorMessage(InfoLogLength);
glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL,
&FragmentShaderErrorMessage[0]);
fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]);
// Link the program
fprintf(stdout, "Linking program\n");
GLuint ProgramID = glCreateProgram();
glAttachShader(ProgramID, VertexShaderID);
glAttachShader(ProgramID, FragmentShaderID);
glLinkProgram(ProgramID);
// Check the program
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<char> ProgramErrorMessage( max(InfoLogLength, int(1)) );
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);
glDeleteShader(VertexShaderID);
glDeleteShader(FragmentShaderID);
return ProgramID;
}
But when is run the code in debug mode ( i copied the full code from the Tutorial Files) my programm starts, but than it opens a errorwindow of Microsoft Visual C++ 2010 Express, the window contains the following error:
Unhandled exception at 0x00000000 in Engine.exe: 0xC0000005: Access violation.
My Debug Console show the following errors/outputs:
'Engine.exe': Loaded 'C:\Users\Domenik\Documents\Visual Studio 2010\Projects\Engine\Debug\Engine.exe', Symbols loaded.
'Engine.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Program Files\AVAST Software\Avast\snxhk.dll', Cannot find or open the PDB file
'Engine.exe': Loaded 'C:\Windows\SysWOW64\opengl32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\glu32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\ddraw.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\dciman32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Users\Domenik\Documents\Visual Studio 2010\Projects\Engine\Debug\glew32.dll', Binary was not built with debug information.
'Engine.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'Engine.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'Engine.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\nvoglv32.dll', Cannot find or open the PDB file
'Engine.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\ntmarta.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\Wldap32.dll', Symbols loaded (source information stripped).
'Engine.exe': Loaded 'C:\Windows\SysWOW64\powrprof.dll', Symbols loaded (source information stripped).
The thread 'Win32 Thread' (0xcfc) has exited with code 0 (0x0).
'Engine.exe': Unloaded 'C:\Windows\SysWOW64\powrprof.dll'
The thread 'Win32 Thread' (0x1198) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x538) has exited with code 0 (0x0).
First-chance exception at 0x00000000 in Engine.exe: 0xC0000005: Access violation.
Unhandled exception at 0x00000000 in Engine.exe: 0xC0000005: Access violation.
The thread 'Win32 Thread' (0xdb0) has exited with code -805306369 (0xcfffffff).
The thread 'Win32 Thread' (0x1370) has exited with code -805306369 (0xcfffffff).
The program '[2624] Engine.exe: Native' has exited with code -805306369 (0xcfffffff).
my stack contains this:
00000000()
Engine.exe!main() Line 54 + 0x12 bytes C++
Engine.exe!__tmainCRTStartup() Line 555 + 0x19 bytes C
Engine.exe!mainCRTStartup() Line 371 C
kernel32.dll!#BaseThreadInitThunk#12() + 0x12 bytes
ntdll.dll!___RtlUserThreadStart#8() + 0x27 bytes
ntdll.dll!__RtlUserThreadStart#8() + 0x1b bytes
I had read that the pointer NULL (it find it´s use 4 times in the shader.cpp) can crash the programm if it is to often in use. That sounds so, that i can change them all to 0 or 0L but this don´t fix it.
Can't really see how you are having this problem.
But you may download the the source code from that site.
Run it and compare to your own code.

Another OpenGL SuperBible 5th edition set-up problems

Well, i have just bought this opengl superbible book (5th edition). Unfortunately, i stumbled upon on first chapter as how to set up the opengl itself. Here is the step that i did.
(1) First of all i installed Microsoft Visual Studio 2010 C++ Express.
(2) I downloaded the libraries needed, as for this i downloaded directly from the official site of opengl superbible : http://www.starstonesoftware.com/files/SB5.zip. Then i extracted the files into my local folder.
(3) And then i create new empty project.
File -> New -> Project -> Visual C++ Installed Templates -> General -> Empty Projects
(4) Adding the additional include directories path for freeglut and gltools files header.
Project -> Properties -> Configuration Properties -> (then i set the configuration = All configuration) -> C/C++ -> General -> Additional Include Directories.
here i add two directories :
(a) freeglut : [my local path]\SB5\freeglut-2.6.0\include
(b) gltools : [my local path]\SB5\Src\GLTools\include
(5) Adding the additional dependencies path for also freeglut and gltools files header.
Project -> Properties -> Configuration Properties -> (then i set the configuration = All configuration) -> Linker -> Input -> Additional dependecies.
(a)freeglut_static.lib
(b)GLTools.lib
(6) Adding the library directories.
Project -> Properties -> Configuration Properties -> (then i set the configuration = All configuration) -> VC++ Directories -> Library Directories.
In here i set the locations of directories of freeglut_static.lib and GLTools.lib
(a)freeglut_static.lib : [my local path]\SB5\freeglut-2.6.0\VisualStudio2008Static\Release
(b)GLTools.lib : [my local path]\SB5\VisualStudio2008\GLTools\Release
(7) After that i copy the source code (Triangle.cpp) but i didn't forget to include windows.h at first line.
// Triangle.cpp
// Our first OpenGL program that will just draw a triangle on the screen.
#include <Windows.h>
#include <GLTools.h> // OpenGL toolkit
#include <GLShaderManager.h> // Shader Manager Class
#ifdef __APPLE__
#include <glut/glut.h> // OS X version of GLUT
#else
#define FREEGLUT_STATIC
#include <GL/glut.h> // Windows FreeGlut equivalent
#endif
GLBatch triangleBatch;
GLShaderManager shaderManager;
///////////////////////////////////////////////////////////////////////////////
// Window has changed size, or has just been created. In either case, we need
// to use the window dimensions to set the viewport and the projection matrix.
void ChangeSize(int w, int h)
{
glViewport(0, 0, w, h);
}
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
// Blue background
glClearColor(0.0f, 0.0f, 1.0f, 1.0f );
shaderManager.InitializeStockShaders();
// Load up a triangle
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f };
triangleBatch.Begin(GL_TRIANGLES, 3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
triangleBatch.Draw();
// Perform the buffer swap to display back buffer
glutSwapBuffers();
}
///////////////////////////////////////////////////////////////////////////////
// Main entry point for GLUT based programs
int main(int argc, char* argv[])
{
gltSetWorkingDirectory(argv[0]);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800, 600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
GLenum err = glewInit();
if (GLEW_OK != err) {
fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
return 1;
}
SetupRC();
glutMainLoop();
return 0;
}
(8) After step 7 i build the project and everything still went smoothly. Here was the build result :
1>------ Build started: Project: superbible1, Configuration: Debug Win32 ------
1> main.cpp
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>GLTools.lib(GLBatch.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLBatch.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info
1>GLTools.lib(glew.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(glew.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info
1>GLTools.lib(GLShaderManager.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLShaderManager.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info
1>GLTools.lib(GLTools.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLTools.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info
1>GLTools.lib(GLTriangleBatch.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLTriangleBatch.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info
1> superbible1.vcxproj -> C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\superbible1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
(9) The problem came when i run the program. I get runtime error. There was an alert dialog with this message :
Unhandled exception at 0x00000000 in superbible1.exe: 0xC0000005: Access violation reading location 0x00000000.
When i choose to break the program, the cursor was stoped in this line :
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f };
Well if i change this code with another simple code (from opengl redbook). For example like this :
#define FREEGLUT_STATIC
#include <Windows.h>
#include <GL\glut.h>
void display(void)
{
/* clear window */
glClear(GL_COLOR_BUFFER_BIT);
/* draw unit square polygon */
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
/* flush GL buffers */
glFlush();
}
void init()
{
/* set clear color to black */
/* glClearColor (0.0, 0.0, 0.0, 0.0); */
/* set fill color to white */
/* glColor3f(1.0, 1.0, 1.0); */
/* set up standard orthogonal view with clipping */
/* box as cube of side 2 centered at origin */
/* This is default view and these statement could be removed */
/* glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); */
}
int main(int argc, char** argv)
{
/* Initialize mode and open a window in upper left corner of screen */
/* Window title is name of program (arg[0]) */
/* You must call glutInit before any other OpenGL/GLUT calls */
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("simple");
glutDisplayFunc(display);
init();
glutMainLoop();
}
The application can run well. So i thought maybe there was something wrong with the code or probably there was something that i miss. So anyone can help?
I am just starting on this as well.
If you are going to work through all the examples it is better to copy all the freeglut/GLTools .h and .lib files into the relevant directories of VC++2010.
You will still have to include the windows.h in the source and still have to specifically tell VC++2010 use GLTools.lib(Linker,Input,Additional Dependancies).
This
apparently explains how to get rid of all the pdb errors if they bother you.
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, ... can't be the problem. butVisual's green debugging cursor show the NEXT line that will be executed, so I suspect that it's shaderManager.InitializeStockShaders(); that crashes.
I have no idea what this does, but it probably reads files... make sure it finds them. In particular, running the .exe directly from the Explorer from a directory that seems to make sense, depending on the contents of the zip.