Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

OpenGL + C++, varying, glsl - nagły crash..

Ostatnio zmodyfikowano 2013-06-17 14:18
Autor Wiadomość
p4vv37
Temat założony przez niniejszego użytkownika
OpenGL + C++, varying, glsl - nagły crash..
» 2013-06-12 22:09:02
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_03

I... 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
C/C++
/* Using the standard output for fprintf */
#define GLEW_STATIC
#include <windows.h>

#include <iostream>
#include <cstdio>
/* Using the standard output for fprintf */
#include <stdlib.h>
/* Use glew.h instead of gl.h to get all the GL prototypes declared */
#include <GL/glew.h>
/* Using the GLUT library for the base windowing setup */
#include <GL/glut.h>
#include "shader_utils.h"
/* ADD GLOBAL VARIABLES HERE LATER */
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()
{
    /* Clear the background as white */
    glClearColor( 1.0, 1.0, 1.0, 1.0 );
    glClear( GL_COLOR_BUFFER_BIT );
   
    glUseProgram( program );
    glEnableVertexAttribArray( attribute_coord2d );
   
    /* Describe our vertices array to OpenGL (it can't guess its format automatically) */
    glBindBuffer( GL_ARRAY_BUFFER, vbo_triangle );
    glEnableVertexAttribArray( attribute_v_color );
    glBindBuffer( GL_ARRAY_BUFFER, vbo_triangle_colors );
    glVertexAttribPointer(
    attribute_v_color, // attribute
    3, // number of elements per vertex, here (r,g,b)
    GL_FLOAT, // the type of each element
    GL_FALSE, // take our values as-is
    0, // no extra data between each position
    0 // offset of first element
    );
   
    /* Push each element in buffer_vertices to the vertex shader */
    glDrawArrays( GL_TRIANGLES, 0, 3 );
    glDisableVertexAttribArray( attribute_coord2d );
    glDisableVertexAttribArray( attribute_v_color );
   
    /* Display the result */
    glutSwapBuffers(); }

void free_resources()
{
    glDeleteProgram( program );
    glDeleteBuffers( 1, & vbo_triangle );
}

int main( int argc, char * argv[] )
{
   
   
    /* Glut-related initialising functions */
    glutInit( & argc, argv );
    glutInitDisplayMode( GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH );
   
    glutInitWindowSize( 640, 480 );
    glutCreateWindow( "Projekt - grafika 2013" );
   
    /* Extension wrangler initialising */
    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;
    }
   
    /* When all init functions runs without errors,
      the program can initialise the resources */
    if( 1 == init_resources() )
    {
        /* We can display it if everything goes OK */
        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        glutDisplayFunc( onDisplay );
       
        glutMainLoop();
    }
   
    /* If the program exits in the usual way,
      free resources and exit with a success */
    free_resources();
    return EXIT_SUCCESS;
}

Oraz shadery:

fragment:
C/C++
varying vec3 f_color;
void main( void ) {
    gl_FragColor = vec4( 1, 0, f_color.z, 1.0 );
}
vertex:
C/C++
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.
P-85455
pekfos
» 2013-06-12 22:11:10
Próbowałeś debugować?
P-85456
p4vv37
Temat założony przez niniejszego użytkownika
» 2013-06-12 22:17:30
Właśnie debugowałem.

Kiedy idę linia po linii, wywala przy rozpoczęciu mainloop, lub przy dojściu do:
glDrawArrays( GL_TRIANGLES, 0, 3 );
Nie jestem pewien jak rozumieć...

#0 77AD15DE ntdll!LdrQueryProcessModuleInformation() (C:\Windows\system32\ntdll.dll:??)
#1 77AD15DE ntdll!LdrQueryProcessModuleInformation() (C:\Windows\system32\ntdll.dll:??)
#2 77AC014E ntdll!LdrFindResource_U() (C:\Windows\system32\ntdll.dll:??)
#3 0028F68C ?? () (??:??)
#4 581B2392 ??() (C:\Windows\SysWOW64\nvoglv32.dll:??)
#5 581B2D61 ??() (C:\Windows\SysWOW64\nvoglv32.dll:??)
#6 57B15E1B ??() (C:\Windows\SysWOW64\nvoglv32.dll:??)
#7 0042AD60 onDisplay() (D:\Dane\Dropbox\StudiaII\AGH\gk\gkII\GrafikaUp\main.cpp:100)
#8 100035F0 glutPostWindowRedisplay() (C:\PROGRA~2\CODEBL~1\MinGW\bin\glut32.dll:??)

Ostatnie wpisy w Debuggerze:

#7  0x0042ad60 in onDisplay () at D:[...]\main.cpp:100
D:[...]\main.cpp:100:3049:beg:0x42ad60
Continuing...
[Inferior 1 (process 6216) exited with code 030000000005]
Debugger finished with status 0

//Jestem dość początkujący, jeśli odpowiedź jest oczywista i powyżej ją widać, wybaczcie, ale ja nie dostrzegam jeszcze..

[EDIT]

glDrawArrays powoduje crash. Z tego co czytam, przekraczam rozmiar bufora..

Jeszcze dorzucę informację z verysleepy:
P-85458
DejaVu
» 2013-06-17 14:18:49
Jeżeli dobrze zrozumiałem to problem już rozwiązałeś :) Jak coś to jeszcze dorzucam przykład użycia glDrawArrays :)
http://www.songho.ca/opengl/gl_vertexarray.html

C/C++
GLfloat vertices[] = {...}; // 36 of vertex coords
...
// activate and specify pointer to vertex array
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 3, GL_FLOAT, 0, vertices );

// draw a cube
glDrawArrays( GL_TRIANGLES, 0, 36 );

// deactivate vertex arrays after drawing
glDisableClientState( GL_VERTEX_ARRAY );
P-85731
« 1 »
  Strona 1 z 1