3 Replies - 555 Views - Last Post: 16 March 2018 - 03:57 PM Rate Topic: -----

#1 Bihar Shooter   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 39
  • Joined: 13-February 18

GLFW , Glew (OpenGL) code not working

Posted 15 March 2018 - 05:49 PM

I use codeblocks 16.01 ,my code is not working , opengl window turns white and then crashes
+ I have included the libraries that I have linked , please see that if I have linked correct ones.

 

#include <GL/glew.h>
#include "GLFW/glfw3.h"
#include <conio.h>
#include <iostream>


int main(void)
{

    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;



    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(800, 600, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }



    /* Make the window's context current */
    glfwMakeContextCurrent(window);
        if  ( glewInit() != GLEW_OK )
              std::cout<<"Error!"<<std::endl;

    float positions [6] = {
        -0.5,-0.5,
        0,0.5,
        0.5,-0.5

    };
    unsigned int buffer;                            //ID for buffer

    glGenBuffers(1,&buffer);
    glBindBuffer(GL_ARRAY_BUFFER,buffer);           //Put 'type' of buffer into buffer var
    glBufferData(GL_ARRAY_BUFFER,6 *sizeof(float),positions,GL_STATIC_DRAW);    //put data in buffer var as to what , where , usage and visibility to be used

   glBindBuffer(GL_ARRAY_BUFFER,0);

   glEnableVertexAttribArray(0);
    glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(float)*2,0);



    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);


        glDrawArrays(GL_TRIANGLES,0,3);   //Drawing data present in buffer var


        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();

    }

    glfwTerminate();
    return 0;
}




my IDE shows a warning - :corrupt .drective at end of def file
I have defined GL_STATIC in build options/compiler settings/defines

here are the libraries that i have linked -
glew32s
gdi32
glfw32
opengl32

Is This A Good Question/Topic? 0
  • +

Replies To: GLFW , Glew (OpenGL) code not working

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14925
  • View blog
  • Posts: 59,580
  • Joined: 12-June 08

Re: GLFW , Glew (OpenGL) code not working

Posted 15 March 2018 - 05:58 PM

Are you using the right libraries?
Was This Post Helpful? 0
  • +
  • -

#3 Bihar Shooter   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 39
  • Joined: 13-February 18

Re: GLFW , Glew (OpenGL) code not working

Posted 15 March 2018 - 06:30 PM

I think so,
the tutorial that I follow is done MVS 2016 , and I am following it on codeblocks
can it be because of codeblocks ?
Was This Post Helpful? 0
  • +
  • -

#4 Bihar Shooter   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 39
  • Joined: 13-February 18

Re: GLFW , Glew (OpenGL) code not working

Posted 16 March 2018 - 03:57 PM

The program works fine if I remove this line {The 45th line}
glBindBuffer(GL_ARRAY_BUFFER,0);


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1