problem z shaderami w OpenGL

0

Witam, ostatnio staram się nauczyć OpenGLa i shaderów. korzystajac z kodu zrodlowego programu z tutoriala nr. 4 ze strony www.ogldev.atspace.co.uk/index.html wypociłem program, który, dopóki ma wykomentowaną funkcję odpowiadającą za całą zabawę z shaderami, działa tak jak powinien. niestety gdy już próbuję ją włączyć okno programu (białe) mignie i znika.
Wszystko co mi po tym wywala Visual Studio C++ 2010 EE to to:

'Open1.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Program Files\AVAST Software\Avast\snxhk.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\opengl32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\glu32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\ddraw.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\dciman32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'Open1.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'Open1.exe': Loaded 'C:\Users\Marek\Documents\Visual Studio 2010\Projects\Open1\Debug\freeglut.dll', Binary was not built with debug information.
'Open1.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\nvoglv32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\wintrust.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\crypt32.dll', Cannot find or open the PDB file
'Open1.exe': Loaded 'C:\Windows\SysWOW64\msasn1.dll', Cannot find or open the PDB file
The thread 'Win32 Thread' (0x1390) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xcdc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x724) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x132c) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0xcb4) has exited with code 1 (0x1).
The program '[4204] Open1.exe: Native' has exited with code 1 (0x1).

Mógłby ktoś wskazać błędy, które popełniam i ewentualnie doradzic?:)

oto kod programu:

#include <iostream>
#include <string>
#define GLEW_STATIC
#include <GLEW\glew.h>
#include <GL\freeglut.h>
#include <GL\gl.h>



static const char* pFS = "								\n\
				 #version 330				\n\
				 out vec4 FragColor;			\n\
										\n\
				 void main(){				\n\
				 FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);	\n\
				 }";
static const char* pVS = "								\n\
				 #version 330				\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.0f)	\n\
				 }";


#define DIM 2				// 2D, 3D
#define AMMOUNT 4			//ile punktow w vertexBufferData
#define WIDTH 1440			//szerokosc 
#define HEIGHT 900			//wysokosc 

static struct res{
    GLuint vertex_buffer, element_buffer, color_buffer;
}g_resources ;

static const GLfloat vertexBufferData[AMMOUNT*DIM] = {-0.5f, 0.0f,
										   0.0f, 0.0f,
										  -0.5f, 0.5f,
						                                   0.0f, 0.5f};
static const GLshort indices[AMMOUNT]= {0,1,2,3};

static int MakeResources();
static GLuint MakeTexture(const char *filename);
static GLuint MakeBuffer(GLenum target, const void *buffer_data,
						  GLsizei buffer_size);
static void Render(void);
static void update_fade_factor(void);
static void AddShader(GLuint ShaderProgram, const char* pShaderText, GLenum ShaderType);
static void CompileShaders();

int main(int argc, char *argv[])
{

	glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(WIDTH, HEIGHT);
    glutCreateWindow("Hello World");
	GLenum res = glewInit();									
    if (res != GLEW_OK) {
      fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
      return 1;
    }														
    glutDisplayFunc(&Render);
    glutIdleFunc(&update_fade_factor);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	MakeResources();

    glutMainLoop();

}

static int MakeResources(){

	//binduje etc. bufory wierzcholkow i indice'ow
	g_resources.vertex_buffer = MakeBuffer(GL_ARRAY_BUFFER, vertexBufferData, 
											3*4*sizeof(GL_FLOAT));
	g_resources.element_buffer = MakeBuffer(GL_ELEMENT_ARRAY_BUFFER, indices,
											 sizeof(indices));
		CompileShaders();
	
	return 1;
}
static void Render(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnableVertexAttribArray(0);

	glBindBuffer(GL_ARRAY_BUFFER, g_resources.vertex_buffer);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_resources.element_buffer);
	
	 
	glVertexAttribPointer(0, DIM, GL_FLOAT, GL_FALSE, 0, 0);

	glDrawRangeElements(GL_QUAD_STRIP, 0, 4, AMMOUNT, GL_UNSIGNED_SHORT, 0);


	glDisableVertexAttribArray(0);
    glutSwapBuffers();
}
static void update_fade_factor(void){};

static GLuint MakeBuffer(GLenum target, const void *buffer_data,
						  GLsizei buffer_size)
{
    GLuint buffer;
    glGenBuffers(1, &buffer);
	glBindBuffer(target, buffer);
    glBufferData(target, buffer_size, buffer_data, GL_STATIC_DRAW);
    return buffer;
}
static void AddShader(GLuint ShaderProgram, const char* pShaderText, GLenum ShaderType)
{
	GLuint ShaderObject = glCreateShader(ShaderType);
	if(!ShaderObject)
		std::cout <<"Shader nie zaladowan\n";

	const GLchar *p[1];
	p[0] = pShaderText;
	GLint lenght[1];
	lenght[0] = strlen(pShaderText);
	glShaderSource(ShaderObject, 1, p, lenght);
	glCompileShader(ShaderObject);
	GLint success;
	glGetShaderiv(ShaderObject, GL_COMPILE_STATUS, &success);
    if (!success) {
        GLchar InfoLog[1024];
        glGetShaderInfoLog(ShaderObject, 1024, NULL, InfoLog);
        fprintf(stderr, "Error compiling shader type %d: '%s'\n", ShaderType, InfoLog);
        exit(1);
    }
	glAttachShader(ShaderProgram, ShaderObject);
}
static void CompileShaders()
{
	GLuint ShaderProgram = glCreateProgram();
	if (ShaderProgram == 0) {
        fprintf(stderr, "Error creating shader program\n");
        exit(1);
    }

	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);
        exit(1);
	}

	glValidateProgram(ShaderProgram);
    glGetProgramiv(ShaderProgram, GL_VALIDATE_STATUS, &Success);
    if (!Success) {
        glGetProgramInfoLog(ShaderProgram, sizeof(ErrorLog), NULL, ErrorLog);
        fprintf(stderr, "Invalid shader program: '%s'\n", ErrorLog);
        exit(1);
    }

    glUseProgram(ShaderProgram);
} 
0

Co to za dziwna konstrukcja const GLchar *p[1]; i jaki jest jej w ogóle cel? A to GLint lenght[1]; lenght[0] = strlen(pShaderText); jest jeszcze dziwniejsze.

0

Masz rację, że głupio zrobione, poprawiłem na, odpowiednio:

	
const GLchar *p;
p = pShaderText;
GLint lenght;
lenght = strlen(pShaderText);
glShaderSource(ShaderObject, 1, &p, &lenght); 

co nie zmienia faktu ze w żaden sposób nie wpłynęło to na "działanie" programu.

1 użytkowników online, w tym zalogowanych: 0, gości: 1