Hello Guest

OpenGL Superbible questions

  • 5 Replies
  • 12155 Views
OpenGL Superbible questions
« on: January 26, 2011, 21:53:41 »
I recently acquired OpenGL Superbible, 5th Edition. After reading in so many places that most of the tutorials you will find alone all contain deprecated code.

The second chapter goes over just creating a basic triangle in the window. But the code they used doesn't quite make sense to me.

Code: [Select]
shaderManager.InitializeStockShaders();
// Load up a triangle
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f };
triangleBatch.Begin(GL_TRIANGLES, 3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();]

According to the book, TriangleBatch is an instance of GLBatch, while shaderManager is a 'GLShaderManager.'

But neither of these seem to be resolved in eclipse. Where can I get access to these? It just seems a lot different than other examples simply drawing the individual vertices. Is it part of GLUT or some other library I may not have added. OpenGL is all new to me, so any advice would be welcomed!

Thanks,
Trinric.

*

Offline kappa

  • *****
  • 1319
Re: OpenGL Superbible questions
« Reply #1 on: January 26, 2011, 21:57:26 »
Start with the LWJGL Basics Tutorials found here, there is an example of drawing a Quad.

Doing a quick search on shaderManager shows that it is a utility method and not part of OpenGL. Have a look at its source here.
« Last Edit: January 26, 2011, 22:06:47 by kappa »

Re: OpenGL Superbible questions
« Reply #2 on: January 26, 2011, 22:10:08 »
I've read all the basic tutorials so far. It's just that Superbible seems to be the only source of modernized openGL and it's hard to follow along with LWJGL if they are using special classes to simplify their code that I don't have easy access to in Java.

I just downloaded the source code for the book, and it uses some of their "GlTools.".

This is the GLBatch code I found (in c++):
Code: [Select]
#ifndef __GL_BATCH__
#define __GL_BATCH__

// Bring in OpenGL
// Windows
#ifdef WIN32
#include <windows.h> // Must have for Windows platform builds
#ifndef GLEW_STATIC
#define GLEW_STATIC
#endif
#include <gl\glew.h> // OpenGL Extension "autoloader"
#include <gl\gl.h> // Microsoft OpenGL headers (version 1.1 by themselves)
#endif

// Mac OS X
#ifdef __APPLE__
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE | TARGET_IPHONE_SIMULATOR
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#define OPENGL_ES
#else
#include <GL/glew.h>
#include <OpenGL/gl.h> // Apple OpenGL haders (version depends on OS X SDK version)
#endif
#endif

// Linux
#ifdef linux
#define GLEW_STATIC
#include <glew.h>
#endif


#include <math3d.h>
#include <GLBatchBase.h>


class GLBatch : public GLBatchBase
    {
    public:
        GLBatch(void);
        virtual ~GLBatch(void);
       
// Start populating the array
        void Begin(GLenum primitive, GLuint nVerts, GLuint nTextureUnits = 0);
       
// Tell the batch you are done
void End(void);
     
// Block Copy in vertex data
void CopyVertexData3f(M3DVector3f *vVerts);
void CopyNormalDataf(M3DVector3f *vNorms);
void CopyColorData4f(M3DVector4f *vColors);
void CopyTexCoordData2f(M3DVector2f *vTexCoords, GLuint uiTextureLayer);

// Just to make life easier...
inline void CopyVertexData3f(GLfloat *vVerts) { CopyVertexData3f((M3DVector3f *)(vVerts)); }
inline void CopyNormalDataf(GLfloat *vNorms) { CopyNormalDataf((M3DVector3f *)(vNorms)); }
inline void CopyColorData4f(GLfloat *vColors) { CopyColorData4f((M3DVector4f *)(vColors)); }
inline void CopyTexCoordData2f(GLfloat *vTex, GLuint uiTextureLayer) { CopyTexCoordData2f((M3DVector2f *)(vTex), uiTextureLayer); }

virtual void Draw(void);
 
// Immediate mode emulation
// Slowest way to build an array on purpose... Use the above if you can instead
        void Reset(void);
       
        void Vertex3f(GLfloat x, GLfloat y, GLfloat z);
        void Vertex3fv(M3DVector3f vVertex);
       
        void Normal3f(GLfloat x, GLfloat y, GLfloat z);
        void Normal3fv(M3DVector3f vNormal);
       
        void Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
        void Color4fv(M3DVector4f vColor);
       
        void MultiTexCoord2f(GLuint texture, GLclampf s, GLclampf t);
        void MultiTexCoord2fv(GLuint texture, M3DVector2f vTexCoord);               
       
    protected:
GLenum primitiveType; // What am I drawing....
       
GLuint uiVertexArray;
GLuint      uiNormalArray;
GLuint uiColorArray;
GLuint *uiTextureCoordArray;
GLuint vertexArrayObject;
       
        GLuint nVertsBuilding; // Building up vertexes counter (immediate mode emulator)
        GLuint nNumVerts; // Number of verticies in this batch
        GLuint nNumTextureUnits; // Number of texture coordinate sets

        bool bBatchDone; // Batch has been built
 

M3DVector3f *pVerts;
M3DVector3f *pNormals;
M3DVector4f *pColors;
M3DVector2f **pTexCoords;

};

#endif // __GL_BATCH__

Re: OpenGL Superbible questions
« Reply #3 on: January 26, 2011, 22:15:38 »
If it has all of the .h and .cc/.cpp files included (which it should), it should be fairly easy to convert all of those to Java/LWJGL...it'll just take a bit of time is all.
cool story, bro

Re: OpenGL Superbible questions
« Reply #4 on: January 27, 2011, 01:42:03 »
Well I'm not very familiar with C, let alone OpenGL, so the special classes they provide are completely foreign to me. I'll see what I can do though.

Re: OpenGL Superbible questions
« Reply #5 on: March 27, 2011, 18:12:16 »
Hi, a friend of mine is working on a Scala LWJGL OpenGL Toolkit named sloth.

Readme:

Quote
This toolkit was created in order to help people work with OpenGL via LWJGL. The problem most people have is that
documentation like the OpenGL SuperBible book makes use of some helper libraries and it becomes quite complex
to follow the book without those.

In this toolkit we will attempt to provide a syntax as close as possible to the code in the book. That would
allow people to use it as they were working on C++.

We chose Scala because it is a much better language to work with than Java while taking full advantage of the JVM
as well as all the libraries and ecosystem.

"Sloth" was chosen as compared to Glut (Gluttony). Feel free to suggest a meaning for the H!
Another alternative was Scala Lwjgl Utility Toolkit... Slut! ;)

I suppose it could be of help.