please help me out, thanks in advance
here is my code.
#include <iostream>
#include <GL\glew.h>
#include <SDL2\SDL.h>
#include “Loads.h”
using namespace std;
int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Window* m_window = SDL_CreateWindow("lesson1", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL);
SDL_GLContext m_context = SDL_GL_CreateContext(m_window);
GLenum res = glewInit();
if (res != GLEW_OK)
{
std::cerr << "Glew failed to initialize!" << std::endl;
}
bool close = false;
SDL_Event e;
GLfloat points[] = {
-0.5f, -0.5f, +0.0f,
+0.1f, +0.0f, +0.0f,
0.5f, -0.5f, +0.0f,
+0.0f, +0.1f, +0.0f,
+0.0f, +0.5f, +0.0f,
0.0f, +0.0f, +0.1f
};
GLuint index[] = { 0, 1, 2 };
GLuint vertexID;
GLuint colorID;
GLuint bufferID;
GLuint indexbuffer;
Shaders shader("./basics");
glGenVertexArrays(1, &vertexID);
glBindVertexArray(vertexID);
glGenBuffers(1, &bufferID);
glBindBuffer(GL_ARRAY_BUFFER, bufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float)*6, 0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 6, (char*)(sizeof(points)*3));
glGenBuffers(1, &indexbuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexbuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(index), index, GL_STATIC_DRAW);
while (close == false)
{
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
close = true;
}
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
shader.bind();
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
shader.bind();
SDL_GL_SwapWindow(m_window);
}
SDL_GL_DeleteContext(m_context);
SDL_DestroyWindow(m_window);
SDL_Quit();
return 0;
}