Writing a Shader in OpenGL

The Cherno · 352K views · 2017 · 28:21

Open on YouTube

Computer graphics & renderingGame programming & enginestutorial

Why Stack Overflow recommends it

Stack Overflow users link it as the tutorial they were following when their shader code fails to compile or shows only a black screen, and when they ask about the concepts it introduces.

Recommended by 0 people across 0 different months, 2018 to 2022.

What it is

A 28-minute episode of The Cherno's OpenGL series in which he writes a basic vertex and fragment shader in C++ and GLSL, compiles and links them, and uses them to draw a coloured triangle. It covers the shader compile helper, the layout(location) attribute, and the basic shader pipeline.

What people said

Cites adamtheguy762 · 2018-08 · Stack Overflow · on “I am struggling to understand and something in shaders”

I am watching thechernoproject tutorials on youtube for opengl and in the writing a shader in opengl episode he defines where the start of the position attribute is in the shader using the line: layout(location = 0) in vec4 positions; but my question is, why does he need to do this because surely when he previously used glVertexAttribPointer like this: glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0); So here he specifies how to read the buffer including the first position attribute index so why does he need to also specify it in the shader like he has above? You can see all this code at 23:22 in the video: [this video]

Cites adamtheguy762 · 2018-08 · Stack Overflow · on “Why does this shader to draw a triangle in opengl not get run multiple times”

I am learning to use OpenGL through some youtube tutorials online. At 24:43 is the code I am talking about: https: [this video] [this video] In the previous video of the series, the guy says that the vertex shader is run 3 times (for a triangle) and the fragment shader is run once for every pixel within the shape however in the video I have linked, there is nothing telling the vertex shader to run 3 times and there is nothing telling the fragment shader to be run multiple times either. Can someone please explain why? Also I am struggling to understand the terminology being used. For example, in the vertex shader is the code: in vec4 position . And in the fragment shader there is the code out vec4 colo

Cites mlerp · 2019-09 · Stack Overflow · on “getting "version not supported" error while compiling shaders on Mac in OpenGL”

here [LINK] is full code if you want to check it out. I have requested core context using your base. now I am getting no errors, but I am still seeing no triangle. this [this video] is the video I am basing my code on. I've followed it and written everything as is in the video but it still doesn't work. could just be a typo I can't really see

Cites Jan Berndt · 2020-02 · Stack Overflow · on “Drawing a line in modern OpenGL”

@Rabbid I am creating a VBO here if I'm not mistaken. I used this to draw a triangle before, simply using 3 instead of 2 vectors. The shaders are some really basic ones I wrote following this tutorial [this video] . They worked for the triangle, but I can still put them into the question if you want.

Cites Gian Laager · 2020-05 · Stack Overflow · on “Syntax error in OpenGl shader that is copied from YouTube”

I trying to learn OpenGl and now I wanted to make a simple red triangle on a black background with vertices and shaders. I copied the code from that YouTube video. [this video] I've changed a view things. That's my code: #include "prec.h" struct Vector2 { float x, y; }; struct TrianglePos { Vector2 a, b, c; }; static unsigned int CompileShader(unsigned int type, const std::string& source) { unsigned int id = glCreateShader(type); const char* src = source.c_str(); glShaderSource(id, 1, &src, nullptr); glCompileShader(id); int result; glGetShaderiv(id, GL_COMPILE_STATUS, &result); if (!result) { int length; glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length); char* message = (char*)alloca(length * sizeo

Cites M. Yusuf Suleman · 2021-06 · Stack Overflow · on “GLFW and GLEW not showing triangle red”

My code does not display a red triangle, instead there is a black screen. I was following the OpenGL tutorial by The Cherno. This happened at end of the 7th episode. I am using Visual Studio 2019 with Visual C++ on Windows 10 Home. My Graphics Card is a NVidia 820m. Link for tutorial I was following. [this video] #include <gl/glew.h> #include <GLFW/glfw3.h> #include <iostream> #include <fstream> static unsigned int CompileShader(unsigned int type, const std::string& source) { unsigned int id = glCreateShader(type); const char* src = source.c_str(); glShaderSource(id, 1, &src, nullptr); glCompileShader(id); int result; glGetShaderiv(id, GL_COMPILE_STATUS, &result); if (result = GL_FALSE) { int leg

Cites KcFnMi · 2022-11 · Stack Overflow · on “Why is OpenGL giving me the error: ERROR: 0:1: '' : version '330' is not supported?”

**need to use VAO in the new version** this piece of information helped me, while I was trying to make [this video] work on macOS