OpenGL + C++, varying, glsl - nagły crash..
Dobry wieczór
Uczę się OpenGL 2.1 za stroną:
http://en.wikibooks.org/wiki/OpenGL_Programming/Wydaje mi się, że to jest świetny kurs, dobiłem już do lekcji trzeciej:
http://en.wikibooks.org/wiki/OpenGL_Programming /Modern_OpenGL_Tutorial_03I... tutaj stqanąłem. Nie mam pojęcia nawet jak przeanalizować błąd, nie pojawia się żadna inforemacja.Problem pojawił się po dodaniu v_color i varying. DO tego miejsca, oraz po usunięciuu varying z shaderów, wszystko działa super.
Wrzucam kod:
main.cpp
#define GLEW_STATIC
#include <windows.h>
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glut.h>
#include "shader_utils.h"
GLuint program;
GLuint vbo_triangle, vbo_triangle_colors;
GLint attribute_coord2d;
GLint attribute_v_color;
int init_resources( void )
{
const char * attribute_name;
GLint compile_ok = GL_FALSE, link_ok = GL_FALSE;
GLuint vs, fs;
if(( vs = create_shader( "D:/Dane/Dropbox/StudiaII/AGH/gk/gkII/GrafikaUp/triangle.v.glsl", GL_VERTEX_SHADER ) ) == 0 ) return 0;
if(( fs = create_shader( "D:/Dane/Dropbox/StudiaII/AGH/gk/gkII/GrafikaUp/triangle.f.glsl", GL_FRAGMENT_SHADER ) ) == 0 ) return 0;
glGetShaderiv( fs, GL_COMPILE_STATUS, & compile_ok );
if( !compile_ok ) {
fprintf( stderr, "Error in fragment shader\n" );
return 0;
}
program = glCreateProgram();
glAttachShader( program, vs );
glAttachShader( program, fs );
glLinkProgram( program );
glGetProgramiv( program, GL_LINK_STATUS, & link_ok );
if( !link_ok ) {
fprintf( stderr, "glLinkProgram:" );
return 0;
}
GLfloat triangle_vertices[] = {
0.0, 0.8,
- 0.8, - 0.8,
0.8, - 0.8,
};
glGenBuffers( 1, & vbo_triangle );
glBindBuffer( GL_ARRAY_BUFFER, vbo_triangle );
glBufferData( GL_ARRAY_BUFFER, sizeof( triangle_vertices ), triangle_vertices, GL_STATIC_DRAW );
GLfloat triangle_colors[] = {
1.0, 1.0, 0.0,
0.0, 0.0, 1.0,
1.0, 0.0, 0.0,
};
glGenBuffers( 1, & vbo_triangle_colors );
glBindBuffer( GL_ARRAY_BUFFER, vbo_triangle_colors );
glBufferData( GL_ARRAY_BUFFER, sizeof( triangle_colors ), triangle_colors, GL_STATIC_DRAW );
attribute_name = "v_color";
attribute_v_color = glGetAttribLocation( program, attribute_name );
if( attribute_v_color == - 1 ) {
fprintf( stderr, "Could not bind attribute %s\n", attribute_name );
return 0;
}
return 1;
}
void onDisplay()
{
glClearColor( 1.0, 1.0, 1.0, 1.0 );
glClear( GL_COLOR_BUFFER_BIT );
glUseProgram( program );
glEnableVertexAttribArray( attribute_coord2d );
glBindBuffer( GL_ARRAY_BUFFER, vbo_triangle );
glEnableVertexAttribArray( attribute_v_color );
glBindBuffer( GL_ARRAY_BUFFER, vbo_triangle_colors );
glVertexAttribPointer(
attribute_v_color,
3,
GL_FLOAT,
GL_FALSE,
0,
0
);
glDrawArrays( GL_TRIANGLES, 0, 3 );
glDisableVertexAttribArray( attribute_coord2d );
glDisableVertexAttribArray( attribute_v_color );
glutSwapBuffers(); }
void free_resources()
{
glDeleteProgram( program );
glDeleteBuffers( 1, & vbo_triangle );
}
int main( int argc, char * argv[] )
{
glutInit( & argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH );
glutInitWindowSize( 640, 480 );
glutCreateWindow( "Projekt - grafika 2013" );
GLenum glew_status = glewInit();
if( !GLEW_VERSION_2_0 ) {
fprintf( stderr, "Error: your graphic card does not support OpenGL 2.0\n" );
return 1;
}
if( glew_status != GLEW_OK )
{
fprintf( stderr, "Error: %s\n", glewGetErrorString( glew_status ) );
return EXIT_FAILURE;
}
if( 1 == init_resources() )
{
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glutDisplayFunc( onDisplay );
glutMainLoop();
}
free_resources();
return EXIT_SUCCESS;
}
Oraz shadery:
fragment:
varying vec3 f_color;
void main( void ) {
gl_FragColor = vec4( 1, 0, f_color.z, 1.0 );
}
vertex:
attribute vec2 coord2d;
attribute vec3 v_color;
varying vec3 f_color;
void main( void ) {
gl_Position = vec4( coord2d, 0.0, 1.0 );
f_color = v_color;
}
Po uruchomieniu kodu, jeszcze przed tym, jak cokolwiek się pojawi wyświetla się okno:
Program Grafika.exe przestał działać.
Podpis problemu:
Podpis problemu:
Nazwa zdarzenia problemu: APPCRASH
Nazwa aplikacji: GrafikaUp.exe
Wersja aplikacji: 0.0.0.0
Sygnatura czasowa aplikacji: 51b8d400
Nazwa modułu z błędem: nvoglv32.DLL
Wersja modułu z błędem: 9.18.13.1407
Sygnatura czasowa modułu z błędem: 5116d866
Kod wyjątku: c0000005
Przesunięcie wyjątku: 007a21c4
Wersja systemu operacyjnego: 6.1.7601.2.1.0.256.48
Identyfikator ustawień regionalnych: 1045
Dodatkowe informacje 1: 0a9e
Dodatkowe informacje 2: 0a9e372d3b4ad19135b953a78882e789
Dodatkowe informacje 3: 0a9e
Dodatkowe informacje 4: 0a9e372d3b4ad19135b953a78882e789
Proszę powedzcie, gdzie zrobiłem błąd, albo jak go w ogóle odnaleźć? Używam Code::Blocks, sporo linków trzeba było utworzyć, może to ma znaczenie.