I can't believe I haven't looked at this thread before! This is great!
And by that I mean I need help. I'm trying to learn C++ with OpenGL, but it's going really slowly and I'm confused with it. This program is an example from the OpenGL Superbible, but it doesn't work and I'm not sure why.
#include <GLTools.h>
#include <GLShaderManager.h>
#define FREEGLUT_STATIC
#include <GL/glut.h>
GLBatch triangleBatch;
GLBatch squareBatch;
GLShaderManager shaderManager;
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f };
void ChangeSize(int w,int h)
{
glViewport(0,0,w,h);
}
void SetupRC()
{
glClearColor(0.0f,0.0f,0.0f,1.0f);
shaderManager.InitializeStockShaders();
triangleBatch.Begin(GL_TRIANGLES, 3);
triangleBatch.CopyVertexData3f (vVerts);
triangleBatch.End();
}
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GLfloat vRed[] = {1.0f, 0.0f, 1.0f};
shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
triangleBatch.Draw();
glutSwapBuffers();
}
void SpecialKeys(int key, int x, int y)
{
GLfloat stepSize = 0.025;
GLfloat blockX = vVerts[0];
GLfloat blockY = vVerts[7];
if (key == GLUT_KEY_UP)
{ blockY += stepSize;}
vVerts[0]=blockX;
vVerts[1]=blockY;
vVerts[3]=blockX;
vVerts[4]=blockY;
vVerts[6]=blockX;
vVerts[7]=blockY;
vVerts[9]=blockX;
vVerts[10]=blockY;
squareBatch.CopyVertexData3f(vVerts);
glutPostRedisplay();
}
int main(int argc, char* argv[])
{
gltSetWorkingDirectory(argv[0]);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize (800, 600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
GLenum err = glewInit();
if (GLEW_OK != err)
{
fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
return 1;
}
SetupRC();
glutSpecialFunc(SpecialKeys);
glutPostRedisplay();
glutMainLoop();
return 0;
}
It's supposed to make a triangle appear on the screen (which it does) and the triangle is supposed to move up when you press the up arrow (but it doesn't). Could anyone point out what I'm doing wrong? It uses FreeGLUT and GLTools.
Also, if this isn't the kind of thread where you post stuff like this, my bad. Sorry.