Results 1 to 5 of 5

Thread: Superbible 5ed Chapter6 Shaded Triangle Example

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2011

    Superbible 5ed Chapter6 Shaded Triangle Example

    My exact problem is thus:

    The triangle renders as black. Initially I thought I was rendering nothing at all but then I changed the clearing colour to a medium grey, and lo, there is a black triangle.

    The odd thing is, the same code works just fine on my GF's computer, so it seems it's not so much a problem with the code as it is my computer. I'm having a lot of issues like that though, and I'd like to know why.

    My video card is an ATi Radeon HD4870X2, with the latest drivers. It shouldn't have any problems with OpenGL 3.3 or GLSL 3.30 code, so I'm baffled.

    Any help whatsoever would be greatly appreciated.

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    UK, London

    Re: Superbible 5ed Chapter6 Shaded Triangle Example

    no, your problem is that you want people to help but give them nothing to go on. No code, no screen shots, nothing.
    We could guess, but guess what...why bother.

  3. #3

    Re: Superbible 5ed Chapter6 Shaded Triangle Example

    The usual applies:
    Is glGetError() detecting any errors?
    You mentioned that you are using GL 3.3 and GLSL.
    Are you checking to make sure each vertex shader is compiling.
    Are you checking to make sure each fragment shader is compiling.
    After linking them, are you checking to see if the link succeeded?

    As BionicBytes suggested, you might want to show some code.

    It is possible that you are setting up something and in its default state, it runs on one machine but on ATI, the default state is not good and the output goes who knows where.

    It is also possible that it is a driver bug.

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2011

    Re: Superbible 5ed Chapter6 Shaded Triangle Example

    Ok, thanks V-Man. The code SHOULD be self checking, and it wasn't spitting out any errors. Anyway I'll post the code:

    <div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
    Code :
    // ShadedTriangle.cpp
    // Our first OpenGL program that will just draw a triangle on the screen.
    #include <GLTools.h>            // OpenGL toolkit
    #include <GLShaderManager.h>    // Shader Manager Class
    #ifdef __APPLE__
    #include <glut/glut.h>          // OS X version of GLUT
    #include <GL/glut.h>            // Windows FreeGlut equivalent
    GLBatch	triangleBatch;
    GLShaderManager	shaderManager;
    GLint	myIdentityShader;
    // Window has changed size, or has just been created. In either case, we need
    // to use the window dimensions to set the viewport and the projection matrix.
    void ChangeSize(int w, int h)
    	glViewport(0, 0, w, h);
    // This function does any needed initialization on the rendering context. 
    // This is the first opportunity to do any OpenGL related tasks.
    void SetupRC()
    	// Blue background
    	glClearColor(0.5f, 0.5f, 0.5f, 1.0f ); // I set this to grey to find the black triangle
    	// Load up a triangle
    	GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 
    		                  0.5f, 0.0f, 0.0f,
    						  0.0f, 0.5f, 0.0f };
    	GLfloat vColors [] = { 1.0f, 0.0f, 0.0f, 1.0f,
    		                   0.0f, 1.0f, 0.0f, 1.0f,
    						   0.0f, 0.0f, 1.0f, 1.0f };
    	triangleBatch.Begin(GL_TRIANGLES, 3);
    	myIdentityShader = gltLoadShaderPairWithAttributes("ShadedIdentity.vp", "ShadedIdentity.fp", 2, 
    		                            GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_COLOR, "vColor");
    // Cleanup
    void ShutdownRC()
    // Called to draw scene
    void RenderScene(void)
    	// Clear the window with current clearing color
    	// Perform the buffer swap to display back buffer
    // Main entry point for GLUT based programs
    int main(int argc, char* argv[])
    	glutInit(&amp;argc, argv);
    	glutInitWindowSize(800, 600);
    	glutCreateWindow("Shaded Triangle");
    	GLenum err = glewInit();
    	if (GLEW_OK != err) {
    		fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
    		return 1;
    	return 0;

    Code :
    // The ShadedIdentity Shader
    // ShadedIdentity.vp
    // Vertex Shader
    // Richard S. Wright Jr.
    // OpenGL SuperBible
    #version 130
    in vec4 vColor;
    in vec4 vVertex;
    out vec4 vVaryingColor;
    void main(void) 
        vVaryingColor = vColor;
        gl_Position = vVertex;

    Code :
    // The ShadedIdentity Shader
    // ShadededIdentity.fp
    // Fragment Shader
    // Richard S. Wright Jr.
    // OpenGL SuperBible
    #version 130
    out vec4 vFragColor;
    in vec4 vVaryingColor;
    void main(void)
       vFragColor = vVaryingColor;

    I added some error checking code of my own with glGetError(), and it returns GL_NO_ERROR. It's called just before the main loop, after SetupRC().

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2011

    Re: Superbible 5ed Chapter6 Shaded Triangle Example

    I was very clever and I solved my own problem today! The issue is in one of the provided library functions, CopyColorData4f(). I've had a similar issue with other functions in the library, the solution is to call the function twice. I'm going to look into the source code for that function, but if anyone else has the same problem, that's your solution.

Similar Threads

  1. OpenGL SuperBible 5E, Triangle program background "scattered"
    By kyle.brechin in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-05-2014, 02:21 AM
  2. opengl superbible 5ed triangle problem
    By monkey89 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-13-2011, 11:31 PM
  3. superbible edition 5 triangle move with keys error
    By superbible exsplorer in forum OpenGL: User Software
    Replies: 1
    Last Post: 05-31-2011, 05:02 PM
  4. Blending Shaded 3D textures
    By Tomy in forum OpenGL: GLSL
    Replies: 0
    Last Post: 03-07-2005, 04:59 AM
  5. Shaded Background using OpenGL
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-16-2002, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean