   Displaying a HUD with Shaders
  Hi,I tried to create a HUD for my game.Therefor I have created a shader, which doesn't use the projection matrix, so the result is orthogonal.I use the class HUD to manage my InterfaceHUD::HUD(void) {    float vertices[] = { -512.0f, -384.0f, 0.0f, 1.0f, 512.0f, -384.0f, 0.0f, 1.0f, 512.0f, 384.0f, 0.0f, 1.0f,-512.0f, 384.0f, 0.0f, 1.0f };    float indices[] = { 0, 2, 1, 0, 3, 2 };    // Pass Vertex Data to VBO    glGenBuffers(1, &this->vertices);    glBindBuffer(GL_ARRAY_BUFFER, this->vertices);    glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(GLfloat), &vertices, GL_STATIC_DRAW);    // Pass Index Data to VBO    glGenBuffers(1, &this->indices);    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->indices);    glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(GLuint), &indices, GL_STATIC_DRAW);    // Unbind Buffers    glBindBuffer(GL_ARRAY_BUFFER, 0);    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);}HUD::~HUD(void) {    delete this->tex;}void HUD::render(Shader* shader) {    glDisable(GL_DEPTH_TEST);   glBindBuffer(GL_ARRAY_BUFFER, this->vertices);    shader->enableVAA("vertex", 4, 0);   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->indices);   glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);    shader->disableVAA("vertex");   glBindBuffer(GL_ARRAY_BUFFER, 0);    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);   glEnable(GL_DEPTH_TEST);}The according methods of the shader wrappervoid Shader::enableVAA(const std::string key, const int size, const void* ptr) {GLuint vaa = glGetAttribLocation(this->program_handle, key.c_str());glEnableVertexAttribArray(vaa);    glVertexAttribPointer(vaa, size, GL_FLOAT, GL_FALSE, 0, ptr);}void Shader::disableVAA(const std::string key) {GLint vaa = glGetAttribLocation(this->program_handle, key.c_str());glDisableVertexAttribArray(vaa);   }My Shaders code is the followinguniform mat4 view;in vec4 vertex;in vec3 normal;void main() {    mat4 model = mat4(1.0f);gl_Position = model * view * vertex;}The view matrix is set when enabling the shader in my main render function outside the HUD class, so not displayed here. It works with two other shaders. So I guess also here.out vec4 fragColor;void main() {fragColor = vec4(0.0, 0.0, 0.0, 1.0);}I expected to get a black screen, but the result was nothing. I have seen the scene as usual. Did I set the vertices and indices wrong, or did I make a fundamental error in my rendering?Thank You.   
  In the end, your gl_Position needs to be in homogeneous clip space. That is, each of the x, y, and z components must be between -1.0 and 1.0. This is a special coordinate space where the coordinate refers to the point's position within the frustum. If gl_Position is outside the -1.0 to 1.0 range, it gets clipped, and if all of your points are outside this range, it's possible that the entire polygon they form will get clipped, and you won't see it..Generally, it's the job of the world matrix to move the vertex into world space. It is the job of the view matrix to move the vertex from world space to camera-relative space. And it's the job of the perspective matrix to move the coordinates from this camera-relative view space to the homogeneous coordinate space that I referred to earlier.Your world matrix is identity, and therefore does nothing. Your view matrix, whatever it is, is probably unnecessary, since it looks like your points are defined with respect to the camera already (edit: your z-coordinates are all 0.0, which means that your triangles are in the x/y plane already).What you need is a projection matrix, which you can generate using gluOrtho2D, using -512.0f as the left value, 512.0f as the right, -384.0f as the bottom, and 384.0f as the top. Then, multiply your vertex by this perspective matrix to get the right gl_Position.Edit: Also, depending on what your near plane is, you should set your z-coordinates to something other than zero. If your near plane is 1.0, for instance, you'll want to make sure that your points, in view space, are less than -1.0 (because OpenGL is right-handed, therefore you are staring down the -Z axis, and if your near plane is 1.0, it is going to be 1 unit in that direction, and if your points are at z=0.0 or z=0.5 or something like that, they'll be clipped by the near plane and you won't see them).Edit2: Disregard that last edit if you are using gluOrtho2D. It automatically sets the near and far clipping planes to -1.0 and 1.0, respectively. So, as long as the z-coordinate of your hud vertices are within this range (which they currently are, since they're 0.0), you'll be fine.   ;  Hi,thank you for your explaination, you really helped me understand more about this perspective, view, model matrix thing and also about Vertex Shader.I did as you said, not with gluOrtho2D, but with glm::ortho (I use OpenGL 3.2 Core profile, so I have to get the matrices with GLM).I passed it to the shader and calculate the gl_Positiongl_Position = ortho * vertex;This didn't help, altough the matrix is looking good to meortho[0][0] = 1/512, ortho[1][1] = 1/384, ortho[2][2] = -1 everything else is 0.I also tried to set the z-values to -1 and -2 in a second try. This also didn't help.   ;  Are you sure that ortho[3][3] is 0? It should be 1.   ;  Yeah, sorry, I added the "everything else is 0" later and forgot about [3][3]. Of course it is 1.Edit: I tried something different. I tried to draw a sphere with the HUD shader using the ortho matrix and this is what I got: a few dots outlining a circle where the sphee should be.I know, that the sphere renders fine in the scene.I set those two attributes before renderingglDisable(GL_DEPTH_TEST);glDepthMask(GL_FALSE);I think I can't see the plane, because it is also drawn as a few dots on the outline.[Edited by - Osaic on April 21, 2010 3:39:19 PM]