Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: can someone tell me why this code doesnt work?

  1. #11
    Intern Contributor
    Join Date
    Jun 2013
    Posts
    69
    well i tried the opengl loader generator.
    i generated the files with this code from there website:
    Code :
    lua LoadGen.lua core_4_3 -style=pointer_c -spec=gl -version=4.3 -profile=core -stdext=gl_ubiquitous.txt -stdext=gl_plat_3_3.txt
    my program compiles fine but still crashes. are there any compatibility issues for opengl loader generator? im gonna try gl3w. does opengl loader generator work for any of you?

    here is my code. if you see a problem please let me know:

    Code :
    #include "gl_core_4_3.h"
    #include <GL/gl.h>
    #include <GL/freeglut.h>
    #include <GL/glu.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <stdbool.h>
     
     
    GLuint vao, buffer;
     
    void init();
    void display();
     
    int main(int argc, char **argv){
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGBA);
        glutInitWindowSize(512,512);
        glutInitContextVersion(4,3);
        glutInitContextProfile(GLUT_CORE_PROFILE);
     
        glutCreateWindow("first opengl program");
     
          if(ogl_LoadFunctions() == ogl_LOAD_FAILED)
          {
            printf("error with GLEW");
            exit(1);
          }
     
     
          init();
     
     
        glutDisplayFunc(display);
        glutMainLoop();
     
        return 0;
     
    }
     
    void init()
    {
    	    glGenVertexArrays(1, &vao);
    	    glBindVertexArray(vao);
     
    	    GLfloat vertices[] = {
    	    		-0.90, -0.90,
    	    		0.85, -0.90,
    	    		-0.90, 0.85,
    	    		0.90, -0.85,
    	    		0.90, 0.90,
    	    		-0.85, 0.90
    	    };
    	    glGenBuffers(1, &buffer);
    	    glBindBuffer(GL_ARRAY_BUFFER, buffer);
    	    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
     
    	    const char fshader[] =
    	    	    		"#version 430 core\n"
    	    	    		"out vec4 fColor;\n"
    	    	    		"void main()\n"
    	    	    		"{\n"
    	    	    		"fColor = vec4 (0.0, 0.0, 1.0, 1.0);\n"
    	    	    		"}\n";
     
    	    	const char vshader[] =
    	    	    		"#version 430 core\n"
    	    	    		"layout (location = 0) in vec4 vPosition;\n"
    	    	    		"void main()\n"
    	    	    		"{\n"
    	    	    		"gl_Position = vPosition;\n"
    	    	    		"}\n";
     
    	    		GLuint prog = glCreateProgram();
     
    	    	    GLuint vert = glCreateShader(GL_VERTEX_SHADER);
    	    	    GLuint frag = glCreateShader(GL_FRAGMENT_SHADER);
     
    	    	    GLint vlen = (GLint)strlen(vshader);
    	    	    GLint flen = (GLint)strlen(fshader);
     
    	    	    glShaderSource(vert, 1, &vshader, &vlen);
    	    	    glShaderSource(frag, 1, &fshader, &flen);
    	    	    glCompileShader(vert);
    	    	    glCompileShader(frag);
     
     
    	    	    glAttachShader(prog, vert);
    	    	    glAttachShader(prog, frag);
    	    	    glLinkProgram(prog);
    	    	    glUseProgram(prog);
     
    	    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0,(void *)0);
    	    glEnableVertexAttribArray(0);
    }
     
    void display()
    {
    	glClear(GL_COLOR_BUFFER_BIT);
     
    	glBindVertexArray(vao);
    	glDrawArrays(GL_TRIANGLES, 0, 6);
     
    	glFlush();
    }

    thanks.

  2. #12

  3. #13
    Intern Contributor
    Join Date
    Jun 2013
    Posts
    69
    it crashes in two different places. if i use the function init() after ogl_LoadFunctions() it crashes, but if i copy the code into the main function it crashes at the first glShaderSource(); do you have to call ogl_LoadFunctions() in every function that uses opengl code?

  4. #14
    Junior Member Newbie
    Join Date
    Jul 2011
    Location
    USA
    Posts
    23
    You're trying to get a core profile but you're manually including glu.h and gl.h. I always seem to have trouble if I include those headers. Try getting rid of those and also use glewExperimental if you're using Glew. Personally, I find gl3w to be much easier for core profile but that's all it will load.

  5. #15
    Intern Contributor
    Join Date
    Jun 2013
    Posts
    69
    hey all.
    i just want to thank you all so much for the help. i figured everything out and am super happy. thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •