Is it possible to do any logic with gl lists, I am trying to make a wrapper class for them and I have this code in the compile function:

glNewList(model1,GL_COMPILE);
    glBegin(GL_TRIANGLES);
    int pos=0;
    for (int i=0; i<numcmds; i++)
    {
        if (cmdtype[i]=='v')
        {
            glVertex(cmdarg[pos++],cmdarg[pos++],cmdarg[pos++]);
        }
        else if (cmdtype[i]=='t')
        {
            glTexture(cmdarg[pos++],cmdarg[pos++]);
        }
    }
    glEnd();
    glEndList();

where cmdtype is an array containing either 'v' or 't' specifying whether a vertex of a texture or a shape is being drawn. (I will add more functionality later (EG: Normals, Quads, Colours). The problem is that when I use CallLists on model1 I get a nothing drawn. Does this mean that I cannot have any logic at all between glNewList and glEndList?

The only things that matter between glNewList and glEndList are the OpenGL calls, and they get "frozen" (because they are compiled on the GPU). Any logic conditional statements or whatever can be used to create the OpenGL calls, but once they are created, that's it. DisplayLists themselves cannot record any logic, only the results of the logic, when applied at the construction of the List, it is fixed after that. DisplayLists are also deprecated, so I wouldn't spend much time worrying about those, better concentrate on VBOs and pixel shaders.

I just looked at VBOs, and they look good, except it doesn't look as though I can bind textures to them? Is it possible to bind textures to VBOs?

Of course, VBOs include all the data you like, vertices, texcoords, normals, colors, and more.

I have a problem, I tried making some code to use VBOs and I am getting errors about the ARB functions. They all say ...ARB was not declared in this scope. Am I missing a library? A header?

Check your version of OpenGL and the headers you have. Functions marked with the letters ARB (or EXT, or many others) are extensions to OpenGL which don't exist on older versions, and might have been promoted to official functions in newer versions. Make sure you are up-to-date and that the tutorial code you are using is also up-to-date.

Ok, I got something that isn't giving me errors at compile time, just at runtime. Can anybody see the problem with this class:

#define GL_ARRAY_BUFFER_ARB 0x8892
#define GL_STATIC_DRAW_ARB 0x88E4
typedef void (APIENTRY * PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
typedef void (APIENTRY * PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
typedef void (APIENTRY * PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
PFNGLGENBUFFERSARBPROC glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) wglGetProcAddress("glGenBuffersARB");
PFNGLBINDBUFFERARBPROC glBindBufferARB = (PFNGLBINDBUFFERARBPROC) wglGetProcAddress("glBindBufferARB");
PFNGLBUFFERDATAARBPROC glBufferDataARB = (PFNGLBUFFERDATAARBPROC) wglGetProcAddress("glBufferDataARB");
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) wglGetProcAddress("glDeleteBuffersARB");
class glModel
{
    private:
    unsigned int model;
    unsigned int textu;
    unsigned int norma;

    int numargs;
    float *vex;
    float *tex;
    float *nex;
    public:
    glModel():numargs(0){}
    glModel& Vertex(float tx, float ty, float x, float y, float z);
    void Compile();
    void Draw();
};
glModel& glModel::Vertex(float tx, float ty, float x, float y, float z)//normals will be auto generated every 3 triangles
{
    float *tvex=new float[numargs*3];
    float *ttex=new float[numargs*2];
    for (int i=0; i<numargs*3; i++)
        tvex[i]=vex[i];
    for (int i=0; i<numargs*2; i++)
        ttex[i]=tex[i];
    delete[]vex;vex=0;
    delete[]tex;vex=0;
    vex=new float[numargs*3+3];
    tex=new float[numargs*2+2];
    for (int i=0; i<numargs*3; i++)
        vex[i]=tvex[i];
    for (int i=0; i<numargs*2; i++)
        tex[i]=ttex[i];
    vex[numargs*3]=x;
    vex[numargs*3+1]=y;
    vex[numargs*3+2]=z;
    tex[numargs*2]=tx;
    tex[numargs*2+1]=ty;
    delete[]tvex;tvex=0;
    delete[]ttex;ttex=0;
    numargs++;
    return *this;
}
void glModel::Compile()
{
    glGenBuffersARB(1,&model);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, model);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, numargs*3*sizeof(float), vex, GL_STATIC_DRAW_ARB);
    glGenBuffersARB(1,&textu);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, textu);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, numargs*3*sizeof(float), tex, GL_STATIC_DRAW_ARB);
}
void glModel::Draw()
{
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, model);
    glVertexPointer(3,GL_FLOAT,0,NULL);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, textu);
    glTexCoordPointer(2,GL_FLOAT,0,NULL);
    glDrawArrays(GL_TRIANGLES,0,numargs);
}

Don't use the ARB versions for GenBuffers, BindBuffer, etc. They are now part of standard OpenGL (since version 1.5, which is ancient now). Use glGenBuffers() and related functions.

The kind of hack that you are doing at the start is not recommended at all.

I tried using the non-arb versions, it said that they were all not declared in the scope. Are VBOs really worth the trouble? and if so could you give me some simple sample code to make a short VBO display, say, a triangle?

VBOs are essentially the only drawing method that is viable and not deprecated (display lists and glBegin/glEnd are both deprecated). If you do not have glGenBuffers, glBindBuffer, and other related functions, then your OpenGL version must be either very old (more than 8 years old) or you didn't include the right headers. Make sure you have the latest OpenGL install, and that your header files and link libraries for OpenGL are also up-to-date. These functions are standard functions, if they are not there, then there is something wrong with your installation.

I have version 4.0 I have gl.h and glu.h and glext.h included. All my libraries are properly linked. What am I missing?

You should try this code verbatim, it is the simplest working example, the corresponding tutorial is here. It requires GLUT and GLEW which are pretty useful utility libraries. Note also, that it is required that the "windows.h" be #included before any OpenGL headers.

I looked at all of my GL headers, they are all version 4.0 and none of them contain any of the functions I need? Why am I missing these functions?

Le Update, I re-downloaded the glext.h file and my functions are there... but now I don't have the library to link to. Where can I find the library for glext?

The library for glext.h is, for microsoft, the same opengl32.lib. See here for FAQs. And here for general FAQs.

That is a problem though since it wont link and my libopengl32.a file is working fine. I guess my headers are out of date with my libraries? How do I fix this?

P.S.: This VBO stuff had better be worth all this effort :P

Redownload everything fresh. Don't try to piece stuff together. Make sure you have a recent compiler.

I mean, I am confused now, you seem to be using Windows (based on some posted code), but you have .a extensions to link libraries (indicating MinGW or Cygwin). I would not recommend trying to use OpenGL through Cygwin, if that is what you are trying to do. If using MinGW, make sure you have the latest version installed (GCC 4.5.x) (which should come with the latest OpenGL headers and libs).

For extensions, I would recommend you either use gl3w (you need Python 2.6+ installed) or glew.

That would seem to be the problem, I am using MinGW version 3.4.5. The issue is that I am using Code::Blocks 8.02 and for some reason I really hate the newer versions (I can't stand the sprites :P) Anyways could you tell me how to install a newer version of MinGW and link? it with my version of Code::Blocks?

You can get MinGW from here. And you simply extract the MinGW where it was originally installed by your Code::Blocks IDE (probably within the CB install folder). It should work.

Ok I installed the new MinGW and when I try to build my project I get this error:

Linking executable: bin\Debug\OPENGLTEST.exe
Execution of 'mingw32-g++.exe -L..\..\CodeBlocks\MinGW\lib -LD:\Programming\CodeBlocks\MinGW\MinGW\lib  -o bin\Debug\OPENGLTEST.exe obj\Debug\test1.o   -lopengl32 -lglu32 -lglaux -lopengl32 -lglu32 -lglaux  ..\..\CodeBlocks\MinGW\lib\libglaux.a ..\..\CodeBlocks\MinGW\lib\libglu32.a ..\..\CodeBlocks\MinGW\lib\libopengl32.a D:\Programming\CodeBlocks\MinGW\MinGW\lib\libopengl32.a D:\Programming\CodeBlocks\MinGW\MinGW\lib\libglaux.a D:\Programming\CodeBlocks\MinGW\MinGW\lib\libglu32.a  -mwindows' in 'D:\Programming\C++\OPENGLTEST' failed.
Nothing to be done.

What now?

Please help nothing I do works!!! None of my projects will compile!!! :O

Install the newest version of Code::Blocks (with MinGW), a fresh install.
Other than that, I cannot help you fix problems on your computer / OS / compiler / IDE / OpenGL setup.

I reinstalled and whenever I press the 'Build and Run' button I get this popup in an infinite loop: "It seems this project has not been built yet. Do you what to build it now?" and everytime i press "yes" it shows the same popup. How do I fix this?

Please help, I cannot program at all!

I looked all over that forum, tried everything they suggested and still I get the same problem. When I hit just build I get this message in the build log section:

-------------- Build: Debug in test ---------------

mingw32-g++.exe -Wall -g -I"C:\Program Files\CodeBlocks\MinGW\include" -c D:\Programming\C++\test\main.cpp -o obj\Debug\main.o
Execution of 'mingw32-g++.exe -Wall -g -I"C:\Program Files\CodeBlocks\MinGW\include" -c D:\Programming\C++\test\main.cpp -o obj\Debug\main.o' in 'D:\Programming\C++\test' failed.
Nothing to be done.

Please help me... I haven't done any programming in over a week. :'(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.