You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to work with OpenGL through raylib, but whenever I use an EBO it doesn't work at all. For example, I wrote a small test based on the tutorial from https://learnopengl.com/
I'm trying to draw a square made of two triangles indexed with an EBO, but nothing shows up.
I've included the code below.
Does anyone have an idea why the square isn’t rendering?
float vertices[] = {
-0.5f, -0.5f, 0.0f, //bot left
0.5f, -0.5f, 0.0f, // bot right
-0.5f, 0.5f, 0.0f, // top left
0.5f, 0.5f, 0.0f // top right
};
unsigned int indices[] = {
0, 1, 2, // first triangle: bot left, bot right, top left
1, 3, 2 // second triangle: bot right, top right, top left
};
int main(void)
{
InitWindow(800, 600, "Shader carree");
SetTargetFPS(60);
const char *vs = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
"}\0";
const char *fs = "#version 330 core\n"
"out vec4 FragColor;\n"
"void main()\n"
"{\n"
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
"}\n\0";
Shader shader = LoadShaderFromMemory(vs, fs);
int locColor = GetShaderLocation(shader, "ourColor");
// gen -- Load bind except for the vao one;
unsigned int vao = rlLoadVertexArray(); // generate but don't assign
unsigned int vbo = rlLoadVertexBuffer(vertices, sizeof(vertices), false);
unsigned int ebo = rlLoadVertexBufferElement(indices, sizeof(indices), false);
// no need to enable other it is done in the load function
rlEnableVertexArray(vao);
// set
rlSetVertexAttribute(0, 3, RL_FLOAT, false, 3 * sizeof(float), 0);
rlEnableVertexAttribute(0);
int countFrame = 0;
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(BLACK);
rlEnableShader(shader.id);
rlEnableVertexArray(vao);
//rlDrawVertexArray(0, 3); // from the vao it works but not from the ebo draw 3 vertices
rlDrawVertexArrayElements(0,6,0); // draw nothing
rlDisableVertexArray();
EndDrawing();
countFrame++;
}
UnloadShader(shader);
rlUnloadVertexArray(vao);
rlUnloadVertexBuffer(vbo);
rlUnloadVertexBuffer(ebo);
CloseWindow();
return 0;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone,
I'm trying to work with OpenGL through raylib, but whenever I use an EBO it doesn't work at all. For example, I wrote a small test based on the tutorial from https://learnopengl.com/
I'm trying to draw a square made of two triangles indexed with an EBO, but nothing shows up.
I've included the code below.
Does anyone have an idea why the square isn’t rendering?
Beta Was this translation helpful? Give feedback.
All reactions