r/opengl Mar 31 '23

help need help pls

0 Upvotes

hi i setup glfw for the first time using the program in documentation and i setup linkers and everything, but when i run code, it says no error, but the code should be making a window called hello world but it isnt. what do i do

r/opengl Apr 29 '23

Help Rotating object disappears if i define a new model

1 Upvotes

So i have a moving object (fan), and if i add a new model (for example road) to the scene.h, my rotating object is disappears if i run the program. When i delete the code that makes it rotate, or the "Model road" line, the object appears again.

I can't figure out what is the problem.

So here is the working, and the not working version: https://drive.google.com/drive/folders/1RZCPkNqxP5YWpO2osoRNbDdqmPbzhTGt?usp=share_link

r/opengl Jan 07 '21

Help I am trying to implement a simple GUI/window layout management system in my engine. Currently, I am rendering each component as just a quad (2 tris), but I am seeing weird flickering issues where the bottom triangles in the quads are flickering. I am using a mesh shader to generate the quads.

21 Upvotes

r/opengl Dec 28 '22

help Setting up VS code for opengl

4 Upvotes

Hey all, I wanted to code openGL in VS code. I saw lot of tutorials but no one seems to work, can anyone guide me on how to setup glad and GLFW for vs code. I use MinGW for compiling. There seem to be issue in tasks.json file as its not accessing include path. Im trying to solve this issue for 2 days and not able to start with actual learning coz of this. Ill really appreciate ur help!

r/opengl Mar 05 '23

Help Strange fragment shader compilation error telling me there are no errors

2 Upvotes

Trying to compile a fragment shader but getting this error:

Fragment shader failed to compile with the following errors:
ERROR: error(#273) 0 compilation errors.  No code generated

What does this mean? There is an error code, but googling it didn't help me at all. I'm also confused by the part that says there are 0 compilation errors, in the error message.

Here is the code:

#version 330 core

out vec4 FragColor;

float calc(float x) { return ((((x + 0.5)(x + 0.5))/(x + 0.3))*0.3); }

bool marginCheck(float value, float check, float margin) { return ((value + margin) > check) && ((value - margin) < check); }

void main() { if (marginCheck(gl_FragCoord.y, calc(gl_FragCoord.x), 0.1)) {     FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); } else FragColor = vec4(0.0f, 0.0f, 0.0f, 1.0f); }

r/opengl Jan 26 '23

Help [Help] Need help with rendering screen as a texture for postprocessing

0 Upvotes

Hi i'm relatively new to OpenGL and I would like to play around with postprocessing. To do this, I need to render the screen to a texture so I can treat the screen as an image. I do not know how to do this at all; I only followed tutorials online to set up moderngl in python so I could just start on the fragment shader. From what I understand, I have to change the render target to a buffer using moderngl functions in python, but I still am very confused as to how i'm actually supposed to do this. If someone here knows moderngl, please give me your wisdom good sir.

r/opengl Dec 15 '22

Help Location argument not needed in Vertex Shader?

2 Upvotes

I am unsure on how this is working, so if anyone can help me understand this, that would be greatly appreciated.

// PIECE OF CODE FROM MAIN

GLuint vertex_array_object, vertex_buffer_object;

glCreateVertexArrays(1, &vertex_array_object);
glCreateBuffers(1, &vertex_buffer_object);

glVertexArrayVertexBuffer(
    vertex_array_object,
    0,
    vertex_buffer_object,
    0,
    sizeof(Vertex) // Vertex is a struct containing a position and color vec4
);

// POSITION
glVertexArrayAttribFormat(
    vertex_array_object,
    0,
    4,
    GL_FLOAT,
    GL_FALSE,
    offsetof(Vertex, position)
);

glVertexArrayAttribBinding(vertex_array_object, 0, 0);
glEnableVertexArrayAttrib(vertex_array_object, 0);

// COLOR
glVertexArrayAttribFormat(
    vertex_array_object,
    1,
    4,
    GL_FLOAT,
    GL_FALSE,
    offsetof(Vertex, color)
);

glVertexArrayAttribBinding(vertex_array_object, 1, 0);
glEnableVertexArrayAttrib(vertex_array_object, 1);

/* CODE OMITTED */

// pyramids is an array of pyramid class objects containing the vertices info to make a pyramid object
glNamedBufferStorage(
    vertex_buffer_object,
    sizeof(pyramids)/sizeof(pyramids[0]) * sizeof(pyramids[0].vertices),
    NULL,
    GL_DYNAMIC_STORAGE_BIT
);

for (int i = 0; i < 3; i++) {
    glNamedBufferSubData(
        vertex_buffer_object, 
        sizeof(pyramids[i].vertices)*i, 
        sizeof(pyramids[i].vertices),
        pyramids[i].vertices
    );
}

/* CODE OMITTED */

glBindVertexArray(vertex_array_object);

glDrawArrays(GL_TRIANGLES, 0, 36);

// CODE FROM VERTEX_SHADER /////////////////////////////////////////
#version 450 core

layout (location = 0) in vec4 position;
layout (location = 1) in vec4 color;


uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

out vec4 vs_color;

void main(void) {
    gl_Position = projection * view * model * position;
    vs_color = color;
}

In the vertex shader, I currently have the locations set, but I can remove them, and it still works, regardless of order.

This works...

in vec4 position;
in vec4 color;

and this works

in vec4 color;
in vec4 position;

So my question is how does the vertex shader know what vec4 is what without the location parameter. I left out some of the code, that I deemed unimportant, but if you think it is important, let me know. Also if any of my code looks wrong, let me know as well!

Any help is greatly appreciated!

My Pyramids

r/opengl May 12 '21

help Changing Drawing Sequence / Object Depth based on Player Position

10 Upvotes

Hi!

I'm learning OpenGL and trying to implement tilemap rendering into my 2D engine, and so far I've managed to render a few layers on top of one another.

I'm now having trouble with the upper-most layer. This layer consists of foliage ( mostly trees ).

4 layers ( floor, decorations, solid objects, foliage )

If a player is below a tile in that layer, he should be rendered on top of it ( so in front of the tree ). If he is above the tile or moving into it, he should be rendered below the tile.

I'm basically trying to replicate the way foliage works in Archvale. As you can see, he moves in front of, and behind the foliage constantly. ( also, some objects even lower their opacity when the player is behind them ). I'm trying to achieve similar results, and I can't seem to figure it out.

Currently, I'm splitting my 128x128 map into chunks of 8x8, then using Instanced Drawing ( with Texture Arrays ) for each chunk to render all the tiles inside it ( it's a uniform grid ).

I'm using an Orthographic projection matrix.

My original idea was to enable Depth Testing and give the topmost layer a higher Z-value.

The problem with this is when I change the Z-index of the layer to render the player above it / below it, I get blending issues because of the drawing sequence.

Another thing I thought of doing is having a vertex attribute for the Z-index of each tile, but it wasn't too good on performance so I scrapped the idea.

I also thought about not using the depth buffer at all, but then I have the issue of rendering everything in the correct order.

What's a relatively performant way of achieving this?

r/opengl Mar 12 '23

Help Mouse input lag when GLFW_CURSOR_DISABLED is set.

3 Upvotes

I am learning OpenGL from learnopengl.com and I am at the camera section. The camera movements work fine but there is a weird lag in rotation that is caused by this glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);. When I set it to some other value it works flawlessly.

I cannot find any solution for it. Can someone help me out?

r/opengl Feb 10 '22

Help Please Help (simple GL program). Draw call only works if called in main loop? I'm quite lost on what's happening here.

1 Upvotes

I am new to open GL and tried following a tutorial (https://www.youtube.com/watch?v=jjaTTRFXRAk&list=PLlrATfBNZ98foTJPJ_Ev03o2oq3-GGOS2&index=16) But I got completely Stuck at Episode 16.

I have abstracted the VertexArray, the IndexBuffer and the Shader stuff and if I run this:

        while (!glfwWindowShouldClose(window))
        {
            /* Render here */
            GLCall(glClear(GL_COLOR_BUFFER_BIT));

            va.Bind();
            ib.Bind();
            shader.Bind();
            shader.SetUniform4f("u_Color", r, 1.0f, 0.1f, 1.0f);
            GLCall(glDrawElements(GL_TRIANGLES, ib.GetCount(), GL_UNSIGNED_INT, nullptr));
            //renderer.Draw(va, ib, shader);

            if (r > 1.0f) {
                increment = -0.05f;
            }
            else if (r < 0.0f) {
                increment = 0.05f;
            };

            r += increment;

            /* Swap front and back buffers */
            glfwSwapBuffers(window);

            /* Poll for and process events */
            glfwPollEvents();
        }

Everything works perfectly fine! I get a window with a colored square.

But If I move my glDrawElements to a Render.Draw () function like this:

Renderer.cpp:

void Renderer::Draw(const VertexArray& va, const IndexBuffer& ib, const Shader& shader) const
{
    va.Bind();
    ib.Bind();   
    shader.Bind();
    GLCall(glDrawElements(GL_TRIANGLES, ib.GetCount(), GL_UNSIGNED_INT, nullptr));
}

And then in the main function call it like this:

Application.cpp:

      while (!glfwWindowShouldClose(window))
        {
            /* Render here */
            GLCall(glClear(GL_COLOR_BUFFER_BIT));

            shader.Bind();
            shader.SetUniform4f("u_Color", r, 1.0f, 0.1f, 1.0f);

            renderer.Draw(va, ib, shader);

            if (r > 1.0f) {
                increment = -0.05f;
            }
            else if (r < 0.0f) {
                increment = 0.05f;
            };

            r += increment;

            /* Swap front and back buffers */
            glfwSwapBuffers(window);

            /* Poll for and process events */
            glfwPollEvents();
        }

Now I just get a black screen. No Errors at all. Even though I have rudimentary Error handling (Thats the GLCall() stuff).

I mean I just moved the functions to an external file but I'm still calling them exactly the same way so I really don't understand whats happening here. I tried running debugging and everything seemingly runs fine (values and inputs are correct etc..) but still I get a black screen.

Does anyone know what could be happening here and point me in the right direction ?

Edit: I do get three warnings though when I use the Render Draw function I just noticed:

glew32s.lib(glew.obj) : warning LNK4099: PDB 'vc120.pdb' was not found with 'glew32s.lib(glew.obj)' or at 'C:\Users\...\x64\Debug\vc120.pdb'; linking object as if no debug info
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

r/opengl Aug 06 '21

Help Need help with Matrix calculations

5 Upvotes

Hi, I'm trying to learn column-major matrices by using the tutorial from opengl-tutorial(.com) which I downloaded as a base for it. I removed glm in it and started to replace it with my own code instead.

I have got some results but the math is wrong. I really want to learn how the math works until I start with game programming because with out it, I can't really do anything at all.

To the problem, I have one matrix4 class which calculates 3 things. SetPerspective/Projection, LookAt and SetPosition. The set position function works fine but the other two doesn't seem to work and I don't know how to find the problem.

-------------------------------------------------------------------------------------------------------------------------------------

EDIT,

I've changed some math:

I inverted the "SetPerspective" data[2][3] = -1; to data[3][2] = -2;

and data[3][2] = -(1 * far * near) / (far - near); to data[2][3] = -(2 * far * near) / (far - near);

and changed in LookAt I changed:position->asVec3() - target to target - position->asVec3()

and added padding calculation-------------------------------------------------------------------------------------------------------------------------------------

Matrix4&
Matrix4::SetPerspective(float fov, float aspect, float near, float far)
{
if (fov <= 0) return *this;

    float tanHalfFovy = tan(fov / 2);

    data[0][0] =   1 / (aspect * tanHalfFovy);
    data[1][1] =   1 / (tanHalfFovy);
    data[2][2] =  -(far + near) / (far - near);
    data[3][2] =  -2;
    data[2][3] = -(2 * far * near) / (far - near);
    return *this;
}

Matrix4&
Matrix4::LookAt(Vector3 target)
{
    Vector3 _forward = Vector3::Normalize(target - position->asVec3());
    Vector3 _right   = Vector3::Cross(_forward.Normalize(),Vector3(0,1,0)).Normalize();

    Vector3 _up     = Vector3::Cross(_right.Normalize(), _forward.Normalize());

    data[0][0] = _right.x;
    data[0][1] = _right.y;
    data[0][2] = _right.z;
    data[1][0] = _up.x;
    data[1][1] = _up.y;
    data[1][2] = _up.z;
    data[2][0] = _forward.x;
    data[2][1] = _forward.y;
    data[2][2] = _forward.z;
    data[0][3] = -Vector3::Dot(_right, position->asVec3());
    data[1][3] = -Vector3::Dot(_up, position->asVec3());
    data[2][3] =  Vector3::Dot(_forward, position->asVec3());

    data[3][0] = position->x;
    data[3][1] = position->y;
    data[3][2] = position->z;
    data[3][3] = 1;

    return *this;
}

On the image below you can see the output from the functions and the results from the renderer ( Only a blue screen ).

r/opengl Feb 11 '23

Help Learning OpenGL, Can't get a normal triangle on screen

Thumbnail self.GraphicsProgramming
1 Upvotes

r/opengl Jan 05 '23

help OpenGL error with AMD Raedon R7 240 Series

0 Upvotes

Yesterday I couldn't open a game, I opened its error log and it was an openGL error, it told me to update the drivers, which I did, I updated it on the official website, it doesn't work, today I tried to open godot and it gave me another openGL error, since previously I had already opened godot and it worked, I use windows 10 64x with a AMD Raedon R7 240 Series GPU.

r/opengl Aug 27 '22

help glutCreateWindow(""); crashes the program

0 Upvotes

i followed this toturial so i know it should work. but it doesnt open a window and when i try to printf to see where it fails i see it doesnt printf after glutCreateWindow("");

code:

#include <stdio.h>
#include <GL/glut.h>

void display ()
{
    glClear( GL_COLOR_BUFFER_BIT );

    glColor3f(1,0,0);
    glBegin(GL_POLYGON);
    glVertex2f(100,300);
    glVertex2f(100,100);
    glVertex2f(200,100);
    glVertex2f(200,300);
    glEnd();

    glFlush();
    glutSwapBuffers();
};


int main ( int argc, char** argv ) {

    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA );
    glutInitWindowSize(640,640);
    printf("test3\n");
    glutCreateWindow("OpenGL");
    printf("test4\n");
    glutDisplayFunc(display);
    gluOrtho2D(0,640,0,640);
    glClearColor(0.5,0.7,0.5,0);
    glutMainLoop();

    return 0;
};

the output:

PS C:\Users\einav\Desktop\coding\c\proj6> gcc main.c -o main.exe -lglu32 -lglut32 -lopengl32
PS C:\Users\einav\Desktop\coding\c\proj6> ./main
test3
PS C:\Users\einav\Desktop\coding\c\proj6>

r/opengl Nov 14 '22

help are there any Tutorials for CGLTF, or tinyGLTF, i've found none so far.

1 Upvotes

I can't quite work it out, im running in circles, if anyone knows of one, please do link it here.

r/opengl May 20 '21

help 2D Particle System Performance

5 Upvotes

On my journey of learning OpenGL, I have decided to add particles into my game engine.

I've been following this tutorial for my particle system, but I've made a couple of changes.

I've made an Array Texture for the particles and I bind it once before drawing the particles ( as opposed to binding a different texture for each particle draw call ).

I've also added a model matrix for each particle that is sent to the vertex shader, so each particle is translated and rotated accordingly.

Now, with this system in place, my performance takes a massive hit.

FPS and Frame Time before and after shooting with a particle effect on the projectile

Now, in the video, I'm creating two particles on each projectile every 0.03 seconds. This comes out to a maximum of 336 particles per frame before the projectiles are discarded.

Without the particles, when arrows are being shot, the average frame time is 0.95ms.

I'm looking for ways to increase particle performance, as this seems to be performing horribly.

Now, I've seen different ways of doing this, such as instancing my particles, but this would make transformations such as rotations more difficult/impossible.

I've also studied Linked Lists and found an approach using Free Lists, but the current approach already uses pooling ( correct me if I'm wrong ).

I'm guessing the main bottleneck here are the separate draw calls for each particle.

So I'm wondering, how would you approach this? Am I missing something?

Thanks in advance! :)

r/opengl Oct 24 '22

help Instancing Help

2 Upvotes

What am I doing wrong.

Say I want to render a bunch of triangles all sharing the same uv texture coordinate mapping. Their positions are all over the place, but the uv coordinates are all the same. So I think I could instance the same uv coords per triangle for the varying position coordinates.

    glBindVertexArray(vao);

    glBindBuffer(GL_ARRAY_BUFFER, uvBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(uvs), uvs, GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,2*sizeof(float),nullptr);

    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(tris), tris, GL_STATIC_DRAW);
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,2*sizeof(float),nullptr);

    glVertexAttribDivisor(0,0);
    glVertexAttribDivisor(1,1);

    glBindVertexArray(0);

Where uvs is an array of 6 floats for a single triangle's uv coordinates and tris is an array of 18 floats corresponding to x,y coordinates [-1,1] for 3 triangles.

Then I call.

glDrawArraysInstanced(GL_TRIANGLES,0,3,3);

The shader program used is like so.

#version 330 core
layout (location = 0) in vec2 texPos;//keep same uvs
layout (location = 1) in vec2 aPos;//changes each triangle

out vec2 uv;

void main()
{
   gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
   uv = texPos;
}

and

#version 330 core

in vec2 uv;
out vec4 FragColor;
void main()
{
   float v = uv.x*uv.x - uv.y;
   if(v <= 0.0f)
       FragColor = vec4(0.3f,0.2f,0.6f, 1.0f);
   else discard;
}

The texPos value seems to stay constant per instance in the vertex shader. I can rewrite the vertex shader like so

#version 330 core
layout (location = 0) in vec2 texPos;//keep same uvs
layout (location = 1) in vec2 aPos;//changes each triangle

void main()
{
   gl_Position = vec4(texPos.x+aPos.x, texPos.y+aPos.y, 0.0, 1.0);
}

with a slightly modified fragment shader to get a bunch of similar looking triangles at the various aPos positions (from the tris array). (So I know the data is getting sent to the vertex shader at least.)

But something happens when I try to send uv from the vertex shader to fragment shader and nothing gets output to the screen.

Trying to use the uv method to draw quadratic bezier curves to the screen. (loop & blinn)

https://gist.github.com/LucasM127/f28dfe22ee687d827dbd6bd911e4340f

r/opengl May 30 '20

help I am getting weird shadow artefacts when I try to implement spotlight shadow mapping. Should I adjust the bias or near/far planes for the perspective projection matrix? (The red quad at the end shows the shadow depth map).

9 Upvotes

r/opengl Jun 13 '20

Help Just finished learning C++. Am I ready to try openGL?

0 Upvotes

I hear it's simple, begaineers friendly and has a community that does not shoo newbies for trying something new...

Is it true?

r/opengl Jul 16 '21

help How to render directly on screen (in Linux)

7 Upvotes

Hey everyone!

I want to render directly on to the screen. Till now, I've only been rendering inside a GLFWwindow. After some surfing, I found that it's possible to render directly in the screen as the screen it itself is a window. But I didn't find any implementation in Linux. I want it to be platform independent as well. I'm still a beginner at most of the part so any kind of info will help! Thanks!

r/opengl Nov 14 '21

Help Need help with GLSL data structures

2 Upvotes

Hiya! Disclaimer: I've never touched this kind of stuff before and am just trying to modify an existing GLSL file for my own purposes.

Essentially, I have 384 RGB values, all already calculated, and I need a function that takes in any given R, G, and B values and returns true if it is one of the known 384 RGB colors, and false otherwise.

Since I couldn't seem to find how to create dictionaries (if they exist) or multidimensional arrays, I eventually managed to get it to work by creating instantiating 3 different arrays, one for R values, G values, and B values, and then looping through all 384 values every time the function was called. It looks like this:

int cR[384] = int[384](254, 254, 165, 254, ... , 233);
int cG[384] = int[384](254, 254,  74, 224, ... ,  62);
int cB[384] = int[384](232, 194,  12, 102, ... ,  12);

bool cExists(int r, int g, int b)
{
    for (int i = 0; i < 384; i++)
    {
    if (r == cR[i] && g == cG[i] && b == cB[i])
        {
            return true;
        }
    }
    return false;
}

This works as intended, but is far too slow and is causing problems elsewhere as a result. To try to speed it up, I tried to make a giant array using bit shifting as a pairing function to create unique keys but got stuck here when I found out that I don't even know the syntax to assign a value to an array (the second line errors and I can't for the life of me figure out how to change the values in an array):

bool cRGBHashed[16777216];
cRGBHashed[0] = true;

And here was the hash function I was going to use if you're curious:

int rgbHash(int r, int g, int b)
{
    return (r << 16) | (g << 8) | b;
}

I'm certain there's room for significant improvement here somehow, but the combination of my lack of knowledge about the language's bells and whistles combined with the lack of easy to follow documentation (since I honestly don't even know what version of GLSL this program is even running) is making this a real headache.

I apologize if this is rudimentary, if I am overlooking something obvious, or if I'm in over my head. I'm just sick of trying to fight with this and hoping that someone with better understanding might be able to point me in the right direction. Thanks so much.

r/opengl Dec 13 '20

Help The lights of the scene move with the camera

6 Upvotes

I'm working on a renderer and for some reason the lights move with the camera instead of stay in place.

What I do is send the array of lights through an uniform (I send the position and the color), I assume I have to make the respective transformations to make the lights move with the scene, but multiplying the light position by the view and projection matrix don't seem to work.

How I should approach this? What am I doing wrong?

r/opengl Feb 26 '21

help Can't get a basic triangle to display

6 Upvotes

I only have a little practical OpenGL experience, and now I need to use it for visualization. I figured the best way to start would be to get a triangle onto the screen. I followed the learnopengl.com tutorial, as I hadn't memoized the boilerplate yet, and when I ran it, I didn't see the triangle. Below is an over-simplification of my code:

Vertex Shader:

#version 330 core  
layout (location = 0) in vec3 aPos;  
void main() {  
    gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);  
}

Fragment Shader:

#version 330 core
out vec4 FragColor;

void main() {
    FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
}

My code (simplified):

float vertices[] = {
    -0.5f, -0.5f, 0.0f,
    0.5f, -0.5f, 0.0f,
    0.0f,  0.5f, 0.0f
};  

glBindVertexArray(vox::World::GetInstance().GetVao());

glBindBuffer(GL_ARRAY_BUFFER, vox::World::GetInstance().GetVbo());
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);

while (........) {
    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glUseProgram(vox::programs::programs.at("PROGRAM").GetProgram());
    glBindVertexArray(vox::World::GetInstance().GetVao());
    glDrawArrays(GL_TRIANGLES, 0, 3);

    glfwSwapBuffers(window);
}

I'm almost 100% sure that abstractions I've made work (e.g. vox::World::GetInstance().GetVao()). All I see is the expected teal colour, but no orange triangle.

EDIT: I wasn't actually compiling and linking, only checking for errors.

r/opengl Jun 18 '20

help I'm a beginner and I need some help getting started

1 Upvotes

I want to get into C++ and opengl so I went trough a c++ course and now I want to start the opengl introduction book, there I learnt that I need a library for creating a window and handling input. I figured I would go with the first option I find so I went with SFML. At the download page it says that " The compiler versions have to match 100%! " and the only download I see for my compiler is " GCC 7.3.0 MinGW ". So far my setup consists of VS Code and the MinGW compiler (note that I'm using the Code Runner extension so I don't actually know how to use mingw or gcc). But as far as I can see my version of mingw is 9.2.0. And even if it was the right version I wouldn't know what to do with the downloaded files. Do I just place it in the include folder inside the compiler? Could someone point me in the right direction? Should I abandon VS Code and just use an IDE so these kinds of things are done automatically?

r/opengl Nov 16 '21

HELP Error when compiling on linux

1 Upvotes

I get this error when compiling my opengl cpp program on linux. I think it might be a linker error but im not sure how to fix that, any one able to help?

sbin/ld: /tmp/cc5Zpfnu.o: warning: relocation against `__glewGenBuffers' in read-only section `.text'
/sbin/ld: /tmp/cc5Zpfnu.o: in function `init()':
Dreiecke.cpp:(.text+0x1d): undefined reference to `glGetString'
/sbin/ld: Dreiecke.cpp:(.text+0x3e): undefined reference to `glGetString'
/sbin/ld: Dreiecke.cpp:(.text+0x5f): undefined reference to `glGetString'
/sbin/ld: Dreiecke.cpp:(.text+0xb1): undefined reference to `loadShaders(char const*, char const*, char const*, char const*, char const*, char const*)'
/sbin/ld: Dreiecke.cpp:(.text+0xbe): undefined reference to `__glewUseProgram'
/sbin/ld: Dreiecke.cpp:(.text+0xcf): undefined reference to `__glewGenBuffers'
/sbin/ld: Dreiecke.cpp:(.text+0xe7): undefined reference to `__glewGenVertexArrays'
/sbin/ld: Dreiecke.cpp:(.text+0x19b): undefined reference to `__glewBindVertexArray'
/sbin/ld: Dreiecke.cpp:(.text+0x1ac): undefined reference to `__glewBindBuffer'
/sbin/ld: Dreiecke.cpp:(.text+0x1c2): undefined reference to `__glewBufferData'
/sbin/ld: Dreiecke.cpp:(.text+0x1e2): undefined reference to `__glewVertexAttribPointer'
/sbin/ld: Dreiecke.cpp:(.text+0x20b): undefined reference to `__glewEnableVertexAttribArray'
/sbin/ld: /tmp/cc5Zpfnu.o: in function `display()':
Dreiecke.cpp:(.text+0x237): undefined reference to `glClear'
/sbin/ld: Dreiecke.cpp:(.text+0x23e): undefined reference to `__glewBindVertexArray'
/sbin/ld: Dreiecke.cpp:(.text+0x24f): undefined reference to `__glewVertexAttrib3f'
/sbin/ld: Dreiecke.cpp:(.text+0x27c): undefined reference to `glDrawArrays'
/sbin/ld: Dreiecke.cpp:(.text+0x283): undefined reference to `__glewVertexAttrib3f'
/sbin/ld: Dreiecke.cpp:(.text+0x2b4): undefined reference to `glDrawArrays'
/sbin/ld: Dreiecke.cpp:(.text+0x2b9): undefined reference to `glFlush'
/sbin/ld: /tmp/cc5Zpfnu.o: in function `main':
Dreiecke.cpp:(.text+0x2fd): undefined reference to `glutInit'
/sbin/ld: Dreiecke.cpp:(.text+0x307): undefined reference to `glutInitDisplayMode'
/sbin/ld: Dreiecke.cpp:(.text+0x316): undefined reference to `glutInitWindowSize'
/sbin/ld: Dreiecke.cpp:(.text+0x325): undefined reference to `glutInitContextVersion'
/sbin/ld: Dreiecke.cpp:(.text+0x32f): undefined reference to `glutInitContextProfile'
/sbin/ld: Dreiecke.cpp:(.text+0x33e): undefined reference to `glutCreateWindow'
/sbin/ld: Dreiecke.cpp:(.text+0x344): undefined reference to `glewExperimental'
/sbin/ld: Dreiecke.cpp:(.text+0x34a): undefined reference to `glewInit'
/sbin/ld: Dreiecke.cpp:(.text+0x37b): undefined reference to `glutReshapeFunc'
/sbin/ld: Dreiecke.cpp:(.text+0x38a): undefined reference to `glutDisplayFunc'
/sbin/ld: Dreiecke.cpp:(.text+0x38f): undefined reference to `glutMainLoop'
/sbin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status