Draw 2 triangles porgram
here the source
////////////////////////////////////////////////////
#include<iostream>
using namespace std;
#include “/usr/include/GL/vgl.h”
#include <GL/glut.h>
#include “/usr/include/GL/glew.h”
#include “/usr/include/GL/LoadShaders.h”
#include “/usr/include/GL/gl.h”
// I thimk LoadShaders.h is a custom header or something
// the code is the first practice from opengl programming 8th edition
// with a few include modification that got the libraries to work(complete paths).
enum VAO_IDs { Triangles, NumVAOs };
enum Buffer_IDs { ArrayBuffer, NumBuffers };
enum Attrib_IDs { vPosition = 0 };
GLuint VAOs[NumVAOs];
GLuint Buffers[NumBuffers];
const GLuint NumVertices = 6;
//-----------------------------
//------init
//-----------------------------
void init( void){
glGenVertexArrays(NumVAOs, VAOs);
glBindVertexArray(VAOs[Triangles]);
GLfloat vertices[NumVertices][2] = {
{ -0.90f, -0.90f}, //triangle 1
{ 0.85f, -0.90f },
{ -0.90f, 0.85f },
{ 0.90f, -0.85f }, //triangle 2
{ 0.90f, 0.90f },
{ -0.85f, 0.90f } };
glGenBuffers(NumBuffers, Buffers);
glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
ShaderInfo shaders[] = {
{ GL_VERTEX_SHADER, “triangles.vert” }
{ GL_FRAGMENT_SHADER,“triangles.frag” }
{ GL_NONE, NULL }
};
GLuint program = LoadShaders(Shaders);
glUseProgram(Program);
glVertexAttribPointer(vPosition, 2 , GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(vPosition);
}
//----------------------
// display
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(VAOs[Triangles]);
glDrawArray(GL_TRIANGLES, 0, NumVertices);
glFlush();
}
//--------------------------------------
//main
//
int main (int argc, char** argv)
{
glutInit(&argc, char** argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(512, 512);
glutInitContextVersion(4, 3);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutCreateWindow(argv[0]);
if(glewInit()) {
cerr << “Unable to initialize GLEW … exiting” << endl;
exit(EXIT_FAILURE);
}
init();
glutDisplayFunc(display);
glutMainLoop();
}
//---------------------------------------end--------------------------------------
//---------------------------the compile errors:----------------------------
//----------------------------------------------------------------------------------
I use "g++ /path/to/file.cpp -lm -lGL -lglut
/home/ilan/Desktop/c++/opengl/tr2.cpp: In function ‘void init()’:
/home/ilan/Desktop/c++/opengl/tr2.cpp:36: error: expected ‘}’ before ‘{’ token
/home/ilan/Desktop/c++/opengl/tr2.cpp:36: error: expected ‘,’ or ‘;’ before ‘{’ token
/home/ilan/Desktop/c++/opengl/tr2.cpp:37: error: expected ‘;’ before ‘}’ token
/home/ilan/Desktop/c++/opengl/tr2.cpp: At global scope:
/home/ilan/Desktop/c++/opengl/tr2.cpp:39: error: ‘Shaders’ was not declared in this scope
/home/ilan/Desktop/c++/opengl/tr2.cpp:40: error: expected constructor, destructor, or type conversion before ‘(’ token
/home/ilan/Desktop/c++/opengl/tr2.cpp:41: error: expected constructor, destructor, or type conversion before ‘(’ token
/home/ilan/Desktop/c++/opengl/tr2.cpp:42: error: expected constructor, destructor, or type conversion before ‘(’ token
/home/ilan/Desktop/c++/opengl/tr2.cpp:43: error: expected declaration before ‘}’ token
I read the code a hundred times but cant find where it’s broken (I’m a complete noob)
Help will be greatly appreciated. Thank you.