Odd … I tried drawing with the fixed pipeline once , and then , I re-tried drawing with the old code , and it worked , with the same code !
I swear it didn’t work one second ago …
Edit : Nvm , I was using the fixed pipeline and it worked just well … seems like a problem with my code ; I’ll post it here
private void draw() {
/* Draw Function //
// Put everything that is draw every possible tick here ! */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/*------------------------------------------------*/
glBindBuffer(GL_ARRAY_BUFFER, buffer);
enableVertexAttribs();
// last parameter is obviously the number of vertexes to draw
glDrawArrays(GL_TRIANGLES, 0, 3);
disableVertexAttribs();
glBindBuffer(GL_ARRAY_BUFFER, 0);
/*------------------------------------------------*/
Display.update();
}
// Vertex Attrib List //
// Storing all the vertex attributes in a big editable list //
static LinkedList<Integer> vertexAttribArray = new LinkedList<Integer>();
static int attribNum; // the non 0-based (Makes for looping correct) number of attributes
static int stride; // the distance between each elements of the attributes listin bytes
public static void addVertexAttrib(int VectorType) {
// Basically ; 4 , 3 , 2 , 1
vertexAttribArray.add(VectorType);
//Adds the size of the attrib to the stride
stride += VectorType * 4;
attribNum += 1;
}
public static void enableVertexAttribs() {
int offset = 0; // the offset from the beginning in bytes
for (int i = 0; i < attribNum; i++) {
//Size of the current attribute (is it a Vector2f OR 3f OR 4f ?)
int size = vertexAttribArray.get(i);
/* For testing
System.out.println(new StringBuilder().append("index : ").append(i).append(" | size : ").append(size).append(" | stride : ").append(stride - size * 4).append(" | offset : ").append(offset));*/
glEnableVertexAttribArray(i); //the distance - the current vertex attribute size ;
glVertexAttribPointer(i, size, GL_FLOAT, false, stride - size * 4, offset);
offset += size * 4;
}
}
public static void disableVertexAttribs() {
for (int i = 0; i < attribNum; i++) {
glDisableVertexAttribArray(i);
}
}
#version 330
out vec4 outputColor;
void main()
{
outputColor = vec4(1,1,1,1);
}
#version 330
layout(location = 0) in vec3 Position;
void main()
{
gl_Position = (Position, 1);
}
And after installing codexl , here are the calls I’m having (with a breakpoint at glprogram)
glCreateShader(GL_VERTEX_SHADER)
glShaderSource(1,1,0x…,0x…)
glCompileShader(1)
glGetShaderiv(1,GL_COMPIL
glCreateShader(GL_FRAGMENT_SHADER)
glShaderSource(2,1,0x…,0x…)
glCompileShader(2)
glGetShaderiv(2,GL_COMPILE_STATUS,0x…)
glCreateProgram()
glAttachShader(3,1)
glAttachShader(3,2)
glLinkProgram(3)
glGetProgramiv(3,GL_LINK_STATUS,0x…)
glValidateProgram()
glGetProgramiv(3,GL_VALIDATE_STATUS,0x…)
-> glUseProgram(3)
glGenBuffers(1,0x…)
glBindBuffer(GL_ARRAY_BUFFER,1)
glBufferData(GL_ARRAY_BUFFER,36,0x…,GL_STATIC_DRAW)
glBindBuffer(GL_ARRAY_BUFFER,0)
-> glUseProgram(0)
-> glUseProgram(3)
-> glUseProgram(0)
-> glUseProgram(3)
-> glUseProgram(0)
But I don’t see any glDrawArrays …
The vertex buffer is created properly but it seems that the draw code isn’t working