Well, it doesn’t complain anymore
But still, nothing shows up…
I have never tried using shaders before, so I have no idea, where something could be wrong.
Can you try have a look at my code?
#include <GLUT/GLUT.h>
#include <iostream>
#include <vector>
#include <math.h>
#include "debug.h"
#include "init.h"
#include "userinteraction.h"
#include "camera.h"
using namespace std;
// Global variables
bool EXIT_LOOP = false;
float pi = atan(1)*4;
// Global Objects
Debug debug;
Camera camera;
const char* vertexSource =
"#version 120
"
"varying vec2 position;"
"void main() {"
" gl_Position = vec4( position, 0.0, 1.0 );"
"}";
const char* fragmentSource =
"#version 120
"
"varying vec4 outColor;"
"void main() {"
" outColor = vec4( 1.0, 1.0, 1.0, 1.0 );"
"}";
void display(void)
{
keyOperations();
keySpecialOperations();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(5.0,5.0,5.0);
glDrawArrays( GL_TRIANGLES, 0, 3 );
glutSwapBuffers();
if (EXIT_LOOP) exit(0);
}
int main(int argc, char** argv) {
init(argc, argv);
float vArray[] = {
0.0f, 0.5f,
0.5f, -0.5f,
-0.5f, -0.5f
};
GLuint myvbo;
glGenBuffers(1, &myvbo);
glBindBuffer(GL_ARRAY_BUFFER, myvbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vArray), vArray, GL_STATIC_DRAW);
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexSource, NULL);
glCompileShader(vertexShader);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragmentSource, NULL);
glCompileShader(fragmentShader);
GLuint shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glBindFragDataLocationEXT(shaderProgram, 0, "outColor");
glLinkProgram(shaderProgram);
glUseProgram(shaderProgram);
GLint posAttrib = glGetAttribLocation(shaderProgram, "position");
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(posAttrib);
GLuint vao;
glGenVertexArraysAPPLE(1, &vao);
glBindVertexArrayAPPLE(vao);
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(handleResize);
glutKeyboardFunc(keyPressed);
glutKeyboardUpFunc(keyUp);
glutMainLoop();
return 0;
}