Hello, I was partaking in the global game jam (where you have to try to make a game in 48 hours). I got my game pseudo-finished, but I cannot get it to render the scene properly. Here is the code related to the rendering:

Code for opengl initialization:

glClearColor(0.5f,0.5f,0.5f,1.0f);
float ambLight[]={0.5f,0.5f,0.5f,1.0f};
glLightfv(GL_LIGHT1,GL_AMBIENT,ambLight);
glEnable(GL_LIGHT1);
LoadTextures();
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

Code for opengl drawing (called every frame):

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(FOV,(double)winWidth/(double)winHeight,NEAR_RENDER,FAR_RENDER);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,winWidth,winHeight);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(dty,1.0f,0.0f,0.0f);
glRotatef(dtx,0.0f,1.0f,0.0f);
glTranslatef(-x,PLAYER_HEIGHT_STAND, -y);
glBindTexture(GL_TEXTURE_2D,wall[level]);
glColor3f(1.0f,1.0f,1.0f);
//...
glBindTexture(GL_TEXTURE_2D,ground);
for (int yy=0; yy<mazeDimy; ++yy)
{
    for (int xx=0; xx<mazeDimx; ++xx)
    {
        glBegin(GL_QUADS);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(xx*WALL_LENGTH,FLOOR_HEIGHT,yy*WALL_LENGTH);
            glTexCoord2f(0.0f,1.0f);
            glVertex3f(xx*WALL_LENGTH,FLOOR_HEIGHT,(yy+1)*WALL_LENGTH);
            glTexCoord2f(1.0f,1.0f);
            glVertex3f((xx+1)*WALL_LENGTH,FLOOR_HEIGHT,(yy+1)*WALL_LENGTH);
            glTexCoord2f(1.0f,0.0f);
            glVertex3f((xx+1)*WALL_LENGTH,FLOOR_HEIGHT,yy*WALL_LENGTH);
        glEnd();
    }
}

I have a window showing a gray background (my clear colour) so I know that it set up properly, but for some reason I can't seem to get it to draw any of my quads. Any ideas?

My first guess would be that your generated mesh might be going out of your view frustum.
It would be best to go incrementally. Using an ortho projection is simpler. So, i would suggest the following:
1) Get the mesh to render in ortho, without any transforms(or minimal), just to check what the mesh looks like.
2) Incrementally add other transforms.
3) Finally check with perspective.

this makes things simpler. Hope this helps

PS: Could you please let me know more details of this competition? Thanks!

Edited 3 Years Ago by myk45

I am not too well versed in how OpenGL works (I am still learning it, there is so much to learn) but I don't think that that is the problem because I have already added movement and view controls, and I have tried looking around and moving to no avail. Here is the code for my movement:

    double stheta=sin(dtx*PI180);
double ctheta=cos(dtx*PI180);
int nx=x,ny=y;
if (W||Up||Comma)
{
    ny+=VELOCITY*stheta;
    nx+=VELOCITY*ctheta;
}
if (A||Left)
{
    ny+=VELOCITY*ctheta;
    nx+=VELOCITY*stheta;
}
if (S||Down||O)
{
    ny-=VELOCITY*stheta;
    nx-=VELOCITY*ctheta;
}
if (D||Right||E)
{
    ny-=VELOCITY*ctheta;
    nx-=VELOCITY*stheta;
}
if (Ctrl)
    height=PLAYER_HEIGHT_CROUCH;
else
    height=PLAYER_HEIGHT_STAND;
//Collision detection:
//start with start/end:
if (((end.xi==end.xf)&&(//horizontal wall case
    (x<(end.xi-WALL_WIDTH)&&nx>(end.xi-WALL_WIDTH))||//to the left
    (x>(end.xi+WALL_WIDTH)&&nx<(end.xi+WALL_WIDTH))))||//to the right
    ((end.zi==end.zf)&&(//vertical wall case
    (y<(end.zi-WALL_WIDTH)&&ny>(end.zi-WALL_WIDTH))||//above
    (y>(end.zi+WALL_WIDTH)&&ny<(end.zi+WALL_WIDTH)))))//below
{
    mazeDimx*=size_factors[level];
    mazeDimy*=size_factors[level++];
    if (level>19)
    {
        int sel=MessageBox(NULL,"OMG! You beat all the levels... do you want"
                       " to play again?","YOU WIN!",MB_YESNO);
        if (sel==IDYES)
        {
            mazeDimx=INIT_W;
            mazeDimy=INIT_H;
            level=0;
            GenMaze(mazeDimx,mazeDimy);
        }
        else
        {
            q=true;
            return;
        }
    }
    else
    {
        GenMaze(mazeDimx,mazeDimy);
        nred=ngreen=nblue=MAX_CRUMBS;
    }
}
if (start.xi==start.xf)
{
    if ((x<(start.xi-WALL_WIDTH)&&nx>(start.xi-WALL_WIDTH))||//head-on-ish
        (x>(start.xi-WALL_WIDTH)&&x<start.xi))//sneaky edge-on case
        nx=start.xi-WALL_WIDTH;
    if ((x>(start.xi+WALL_WIDTH)&&nx<(start.xi+WALL_WIDTH))||//head-on-ish
        (x<(start.xi+WALL_WIDTH)&&x>start.xi))//sneaky edge-on case
        nx=start.xi+WALL_WIDTH;
}
if (start.zi==start.zf)
{
    if ((x<(start.zi-WALL_WIDTH)&&nx>(start.zi-WALL_WIDTH))||//head-on-ish
        (x>(start.zi-WALL_WIDTH)&&x<start.zi))//sneaky edge-on case
        nx=start.zi-WALL_WIDTH;
    if ((x>(start.zi+WALL_WIDTH)&&nx<(start.zi+WALL_WIDTH))||//head-on-ish
        (x<(start.zi+WALL_WIDTH)&&x>start.zi))//sneaky edge-on case
        nx=start.zi+WALL_WIDTH;
}
for (int i=0; i<walls.size(); ++i)
{
    if (walls[i].xi==walls[i].xf)
    {
        if ((x<(walls[i].xi-WALL_WIDTH)&&nx>(walls[i].xi-WALL_WIDTH))||
            (x>(walls[i].xi-WALL_WIDTH)&&x<walls[i].xi))//sneaky edge-on
            nx=walls[i].xi-WALL_WIDTH;
        if ((x>(walls[i].xi+WALL_WIDTH)&&nx<(walls[i].xi+WALL_WIDTH))||
            (x<(walls[i].xi+WALL_WIDTH)&&x>walls[i].xi))//sneaky edge-on
            nx=walls[i].xi+WALL_WIDTH;
    }
    if (walls[i].zi==walls[i].zf)
    {
        if ((x<(walls[i].zi-WALL_WIDTH)&&nx>(walls[i].zi-WALL_WIDTH))||
            (x>(walls[i].zi-WALL_WIDTH)&&x<walls[i].zi))//sneaky edge-on
            nx=walls[i].zi-WALL_WIDTH;
        if ((x>(walls[i].zi+WALL_WIDTH)&&nx<(walls[i].zi+WALL_WIDTH))||
            (x<(walls[i].zi+WALL_WIDTH)&&x>walls[i].zi))//sneaky edge-on
            nx=walls[i].zi+WALL_WIDTH;
    }
}
x=nx;y=ny;

And my code for input:

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT *tmp;
short tmpy,tmpx;
switch (uMsg)
{
    case WM_CLOSE:
        PostQuitMessage(0);
    break;

    case WM_DESTROY:
        return 0;

    case WM_KEYDOWN:
        switch (wParam)
        {
            case VK_ESCAPE:Esc=true;break;
            case VK_SPACE:Space=true;break;
            case VK_UP:Up=true;break;
            case VK_DOWN:Down=true;break;
            case VK_RIGHT:Right=true;break;
            case VK_LEFT:Left=true;break;
            case VK_CONTROL:Ctrl=true;break;
            case 'W':W=true;break;
            case 'A':A=true;break;
            case 'S':S=true;break;
            case 'D':D=true;break;
            case ',':Comma=true;break;
            case 'O':O=true;break;
            case 'E':E=true;break;
        }
    break;
    case WM_KEYUP:
        switch (wParam)
        {
            case VK_ESCAPE:Esc=false;break;
            case VK_SPACE:Space=false;break;
            case VK_UP:Up=false;break;
            case VK_DOWN:Down=false;break;
            case VK_RIGHT:Right=false;break;
            case VK_LEFT:Left=false;break;
            case VK_CONTROL:Ctrl=false;break;
            case 'W':W=false;break;
            case 'A':A=false;break;
            case 'S':S=false;break;
            case 'D':D=false;break;
            case ',':Comma=false;break;
            case 'O':O=true;break;
            case 'E':E=true;break;
        }
    break;
    case WM_LBUTTONDOWN:
        LMB=true;
        short tx,ty;

        tx=GET_X_LPARAM(lParam);
        ty=GET_Y_LPARAM(lParam);
        dx=mx-tx;
        dy=my-ty;
        mx=tx;
        my=ty;
    break;
    case WM_SIZING:
        tmp=(RECT*)lParam;
        winWidth=(tmp->right-tmp->left);
        winHeight=(tmp->bottom-tmp->top);
        winLeft=tmp->left;
        winTop=tmp->top;
    break;
    case WM_MOUSEMOVE:
        tmpx=GET_X_LPARAM(lParam);
        tmpy=GET_Y_LPARAM(lParam);
        dx=tmpx-mx;
        dy=tmpy-my;
        mx=tmpx;
        my=tmpy;
    break;
    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

return 0;
}

Edited 3 Years Ago by Labdabeta

Can you show us your game logic loop?

Also what kind of scales are you using?

How long have you tried holding down one of your movement keys for?

Are you sure you're "looking" the right way?

Edited 3 Years Ago by Ketsuekiame

Well I am not sure how easy it will be to debug it all, but here is all of my code as it appears when I compile it:

main.cpp:

#include <windows.h>
#include <windowsx.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <vector>
#include "SOIL.h"
#define PLAYER_HEIGHT_STAND 2.0f
#define PLAYER_HEIGHT_CROUCH 1.0f
#define ROOM_HEIGHT 4.0f
#define FLOOR_HEIGHT -1.0f
#define CRUMB_DIM 0.5f
#define CRUMB_H 1.0f
#define INIT_W 10
#define INIT_H 10
#define MAX_CRUMBS 100
#define FOV 45.0
#define NEAR_RENDER 0.01
#define FAR_RENDER 100.0
#define VELOCITY 0.15
#define WALL_WIDTH 0.1
#define WALL_LENGTH 0.5f
#define LOOK_FACTOR 0.2
#define PI180 0.01745329
#include <iostream>
float size_factors[]={10.0f,1.05f,1.1f,1.15f,1.2f,1.25f,1.3f,1.4f,1.5f,1.6f,
                      1.7f,1.8f,1.9f};
bool Left,Right,Up,Down,W,A,S,D,Space,Ctrl,LMB,RMB,Esc,Comma,O,E;
float dty,dtx,x,y,z,height;
GLuint wall[14],ground,cred,cgreen,cblue,startWall,endWall;
struct WallDef
{
    float xi,xf,zi,zf;
};
std::vector<WallDef> walls;
WallDef start,end;
struct CrumbDef
{
    float x,z;
    GLuint tex;
};
std::vector<CrumbDef> crumbs;
int level,winWidth,winHeight,nred,ngreen,nblue,winLeft,winTop,mazeDimx,mazeDimy;
short mx,my,dy,dx;
#include "MazeMain.h"
#include "MazeStep.h"
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
void EnableOpenGL(HWND hwnd, HDC*, HGLRC*);
void DisableOpenGL(HWND, HDC, HGLRC);

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    winWidth=winHeight=500;
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;

    /* register window class */
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "GLSample";
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;


    if (!RegisterClassEx(&wcex))
        return 0;

    /* create main window */
    hwnd = CreateWindowEx(0,
                          "GLSample",
                          "MazeThru!",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          winWidth,
                          winHeight,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);
    RECT *tmp;
    BOOL b=GetWindowRect(hwnd,tmp);
    winLeft=tmp->left;
    winTop=tmp->top;
    /* enable OpenGL for the window */
    EnableOpenGL(hwnd, &hDC, &hRC);
    MazeMain();
    /* program main loop */
    while (!bQuit)
    {
        /* check for messages */
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        else
        {
            MazeStep(bQuit);
            SwapBuffers(hDC);
        }
    }

    /* shutdown OpenGL */
    DisableOpenGL(hwnd, hDC, hRC);

    /* destroy the window explicitly */
    DestroyWindow(hwnd);
    return 0;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    RECT *tmp;
    short tmpy,tmpx;
    switch (uMsg)
    {
        case WM_CLOSE:
            PostQuitMessage(0);
        break;

        case WM_DESTROY:
            return 0;

        case WM_KEYDOWN:
            switch (wParam)
            {
                case VK_ESCAPE:Esc=true;break;
                case VK_SPACE:Space=true;break;
                case VK_UP:Up=true;break;
                case VK_DOWN:Down=true;break;
                case VK_RIGHT:Right=true;break;
                case VK_LEFT:Left=true;break;
                case VK_CONTROL:Ctrl=true;break;
                case 'W':W=true;break;
                case 'A':A=true;break;
                case 'S':S=true;break;
                case 'D':D=true;break;
                case ',':Comma=true;break;
                case 'O':O=true;break;
                case 'E':E=true;break;
            }
        break;
        case WM_KEYUP:
            switch (wParam)
            {
                case VK_ESCAPE:Esc=false;break;
                case VK_SPACE:Space=false;break;
                case VK_UP:Up=false;break;
                case VK_DOWN:Down=false;break;
                case VK_RIGHT:Right=false;break;
                case VK_LEFT:Left=false;break;
                case VK_CONTROL:Ctrl=false;break;
                case 'W':W=false;break;
                case 'A':A=false;break;
                case 'S':S=false;break;
                case 'D':D=false;break;
                case ',':Comma=false;break;
                case 'O':O=true;break;
                case 'E':E=true;break;
            }
        break;
        case WM_LBUTTONDOWN:
            LMB=true;
            short tx,ty;

            tx=GET_X_LPARAM(lParam);
            ty=GET_Y_LPARAM(lParam);
            dx=mx-tx;
            dy=my-ty;
            mx=tx;
            my=ty;
        break;
        case WM_SIZING:
            tmp=(RECT*)lParam;
            winWidth=(tmp->right-tmp->left);
            winHeight=(tmp->bottom-tmp->top);
            winLeft=tmp->left;
            winTop=tmp->top;
        break;
        case WM_MOUSEMOVE:
            tmpx=GET_X_LPARAM(lParam);
            tmpy=GET_Y_LPARAM(lParam);
            dx=tmpx-mx;
            dy=tmpy-my;
            mx=tmpx;
            my=tmpy;
        break;
        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }

    return 0;
}

void EnableOpenGL(HWND hwnd, HDC* hDC, HGLRC* hRC)
{
    PIXELFORMATDESCRIPTOR pfd;

    int iFormat;

    /* get the device context (DC) */
    *hDC = GetDC(hwnd);

    /* set the pixel format for the DC */
    ZeroMemory(&pfd, sizeof(pfd));

    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW |
                  PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;

    iFormat = ChoosePixelFormat(*hDC, &pfd);

    SetPixelFormat(*hDC, iFormat, &pfd);

    /* create and enable the render context (RC) */
    *hRC = wglCreateContext(*hDC);

    wglMakeCurrent(*hDC, *hRC);
}

void DisableOpenGL (HWND hwnd, HDC hDC, HGLRC hRC)
{
    wglMakeCurrent(NULL, NULL);
    wglDeleteContext(hRC);
    ReleaseDC(hwnd, hDC);
}

MazeMain.h: (acting to hold initialization stuff)

#ifndef MAZE_MAIN_H
#define MAZE_MAIN_H
#include "MazeGen.h"
void LoadTextures()
{
    wall[0]=SOIL_load_OGL_texture("L1.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[1]=SOIL_load_OGL_texture("L2.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[2]=SOIL_load_OGL_texture("L3.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[3]=SOIL_load_OGL_texture("L4.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[4]=SOIL_load_OGL_texture("L5.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[5]=SOIL_load_OGL_texture("L6.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[6]=SOIL_load_OGL_texture("L7.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[7]=SOIL_load_OGL_texture("L8.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[8]=SOIL_load_OGL_texture("L9.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[9]=SOIL_load_OGL_texture("L10.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[10]=SOIL_load_OGL_texture("L11.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[11]=SOIL_load_OGL_texture("L12.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[12]=SOIL_load_OGL_texture("L13.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    wall[13]=SOIL_load_OGL_texture("L14.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    ground=SOIL_load_OGL_texture("floor.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    cred=SOIL_load_OGL_texture("red.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    cblue=SOIL_load_OGL_texture("blue.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    cgreen=SOIL_load_OGL_texture("green.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    startWall=SOIL_load_OGL_texture("start.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
    endWall=SOIL_load_OGL_texture("end.png",
                                  SOIL_LOAD_AUTO,
                                  SOIL_CREATE_NEW_ID,
                                  SOIL_FLAG_INVERT_Y);
}
void StartMusicLoop()
{
    //todo... how?! (note this is because this year's GGJ theme was a sound file)
}
void MazeMain()
{
    glClearColor(0.5f,0.5f,0.5f,1.0f);
    float ambLight[]={0.5f,0.5f,0.5f,1.0f};
    glLightfv(GL_LIGHT1,GL_AMBIENT,ambLight);
    glEnable(GL_LIGHT1);
    LoadTextures();
    glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_SMOOTH);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
    StartMusicLoop();
    //explain controls:
    MessageBox(NULL,
               "This is a simple game, just find your way through the maze.\n"
               "Use WASD or the arrow keys (or ,AOE) to move.\n"
               "Press SPACE to leave a BLUE marker at your position, and\n"
               "Press the left and right mouse buttons to leave RED and GREEN\n"
               "markers, respectively. These markers will be placed at your\n"
               "current position, use them to help you through the mazes!\n"
               "\tGOOD LUCK!",
               "MazeThru Instructions",
               MB_OK|MB_ICONINFORMATION);
    ShowCursor(FALSE);
    GenMaze(INIT_W,INIT_H);
    mazeDimx=INIT_W;
    mazeDimy=INIT_H;
    level=0;
    x=y=z=0;
    nred=ngreen=nblue=MAX_CRUMBS;
}

#endif // MAZE_MAIN_H

MazeStep.h:

#ifndef MAZE_STEP_H
#define MAZE_STEP_H
#include <math.h>
void MazeDraw()
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
  gluPerspective(FOV,(double)winWidth/(double)winHeight,NEAR_RENDER,FAR_RENDER);
    glMatrixMode(GL_MODELVIEW);
    glViewport(0,0,winWidth,winHeight);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glRotatef(dty,1.0f,0.0f,0.0f);
    glRotatef(dtx,0.0f,1.0f,0.0f);
    glTranslatef(-x,height,-y);
    glBindTexture(GL_TEXTURE_2D,wall[level]);
    glColor3f(1.0f,1.0f,1.0f);
    //draw the walls
    for (int i=0; i<walls.size(); ++i)
    {
        glBegin(GL_QUADS);
            glTexCoord2f(0.0f,1.0f);
                glVertex3f(walls[i].xi,ROOM_HEIGHT,walls[i].zi);
            glTexCoord2f(1.0f,1.0f);
                glVertex3f(walls[i].xf,ROOM_HEIGHT,walls[i].zf);
            glTexCoord2f(1.0f,0.0f);
                glVertex3f(walls[i].xf,0,walls[i].zf);
            glTexCoord2f(0.0f,0.0f);
                glVertex3f(walls[i].xi,0,walls[i].zi);
        glEnd();
    }
    //draw the start and end walls:
    glBindTexture(GL_TEXTURE_2D,startWall);
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f,1.0f);
            glVertex3f(start.xi,ROOM_HEIGHT,start.zi);
        glTexCoord2f(1.0f,1.0f);
            glVertex3f(start.xf,ROOM_HEIGHT,start.zf);
        glTexCoord2f(1.0f,0.0f);
            glVertex3f(start.xf,0,start.zf);
        glTexCoord2f(0.0f,0.0f);
            glVertex3f(start.xi,0,start.zi);
    glEnd();
    glBindTexture(GL_TEXTURE_2D,endWall);
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f,1.0f);
            glVertex3f(end.xi,ROOM_HEIGHT,end.zi);
        glTexCoord2f(1.0f,1.0f);
            glVertex3f(end.xf,ROOM_HEIGHT,end.zf);
        glTexCoord2f(1.0f,0.0f);
            glVertex3f(end.xf,0,end.zf);
        glTexCoord2f(0.0f,0.0f);
            glVertex3f(end.xi,0,end.zi);
    glEnd();
    //draw the crumbs
    for (int i=0; i<crumbs.size(); ++i)
    {
        glBindTexture(GL_TEXTURE_2D,crumbs[i].tex);
        glBegin(GL_TRIANGLES);
            glTexCoord2f(0.5f,1.0f);
            glVertex3f(crumbs[i].x,CRUMB_H+CRUMB_DIM,crumbs[i].z);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(crumbs[i].x-CRUMB_DIM,CRUMB_H,crumbs[i].z-CRUMB_DIM);
            glTexCoord2f(1.0f,0.0f);
            glVertex3f(crumbs[i].x+CRUMB_DIM,CRUMB_H,crumbs[i].z-CRUMB_DIM);

            glTexCoord2f(0.5f,1.0f);
            glVertex3f(crumbs[i].x,CRUMB_H+CRUMB_DIM,crumbs[i].z);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(crumbs[i].x+CRUMB_DIM,CRUMB_H,crumbs[i].z-CRUMB_DIM);
            glTexCoord2f(1.0f,0.0f);
            glVertex3f(crumbs[i].x+CRUMB_DIM,CRUMB_H,crumbs[i].z+CRUMB_DIM);

            glTexCoord2f(0.5f,1.0f);
            glVertex3f(crumbs[i].x,CRUMB_H+CRUMB_DIM,crumbs[i].z);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(crumbs[i].x+CRUMB_DIM,CRUMB_H,crumbs[i].z+CRUMB_DIM);
            glTexCoord2f(1.0f,0.0f);
            glVertex3f(crumbs[i].x-CRUMB_DIM,CRUMB_H,crumbs[i].z+CRUMB_DIM);

            glTexCoord2f(0.5f,1.0f);
            glVertex3f(crumbs[i].x,CRUMB_H+CRUMB_DIM,crumbs[i].z);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(crumbs[i].x-CRUMB_DIM,CRUMB_H,crumbs[i].z+CRUMB_DIM);
            glTexCoord2f(1.0f,0.0f);
            glVertex3f(crumbs[i].x-CRUMB_DIM,CRUMB_H,crumbs[i].z-CRUMB_DIM);

            glTexCoord2f(0.5f,1.0f);
            glVertex3f(crumbs[i].x,CRUMB_H-CRUMB_DIM,crumbs[i].z);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(crumbs[i].x-CRUMB_DIM,CRUMB_H,crumbs[i].z-CRUMB_DIM);
            glTexCoord2f(1.0f,0.0f);
            glVertex3f(crumbs[i].x+CRUMB_DIM,CRUMB_H,crumbs[i].z-CRUMB_DIM);

            glTexCoord2f(0.5f,1.0f);
            glVertex3f(crumbs[i].x,CRUMB_H-CRUMB_DIM,crumbs[i].z);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(crumbs[i].x+CRUMB_DIM,CRUMB_H,crumbs[i].z-CRUMB_DIM);
            glTexCoord2f(1.0f,0.0f);
            glVertex3f(crumbs[i].x+CRUMB_DIM,CRUMB_H,crumbs[i].z+CRUMB_DIM);

            glTexCoord2f(0.5f,1.0f);
            glVertex3f(crumbs[i].x,CRUMB_H-CRUMB_DIM,crumbs[i].z);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(crumbs[i].x+CRUMB_DIM,CRUMB_H,crumbs[i].z+CRUMB_DIM);
            glTexCoord2f(1.0f,0.0f);
            glVertex3f(crumbs[i].x-CRUMB_DIM,CRUMB_H,crumbs[i].z+CRUMB_DIM);

            glTexCoord2f(0.5f,1.0f);
            glVertex3f(crumbs[i].x,CRUMB_H-CRUMB_DIM,crumbs[i].z);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(crumbs[i].x-CRUMB_DIM,CRUMB_H,crumbs[i].z+CRUMB_DIM);
            glTexCoord2f(1.0f,0.0f);
            glVertex3f(crumbs[i].x-CRUMB_DIM,CRUMB_H,crumbs[i].z-CRUMB_DIM);
        glEnd();
    }
    glBindTexture(GL_TEXTURE_2D,ground);
    for (int yy=0; yy<mazeDimy; ++yy)
    {
        for (int xx=0; xx<mazeDimx; ++xx)
        {
            glBegin(GL_QUADS);
                glTexCoord2f(0.0f,0.0f);
                glVertex3f(xx*WALL_LENGTH,FLOOR_HEIGHT,yy*WALL_LENGTH);
                glTexCoord2f(0.0f,1.0f);
                glVertex3f(xx*WALL_LENGTH,FLOOR_HEIGHT,(yy+1)*WALL_LENGTH);
                glTexCoord2f(1.0f,1.0f);
                glVertex3f((xx+1)*WALL_LENGTH,FLOOR_HEIGHT,(yy+1)*WALL_LENGTH);
                glTexCoord2f(1.0f,0.0f);
                glVertex3f((xx+1)*WALL_LENGTH,FLOOR_HEIGHT,yy*WALL_LENGTH);
            glEnd();
        }
    }
    //add the lines to the crumbs later if i have time
    //HUD TIME:

    //todo

}
void MazeStep(BOOL &q)
{
    //dealing w/ events 1st:
    if (Esc)
    {
        Esc=false;//process the escape (as it will disappear when the msg ups)
        ShowCursor(TRUE);
        int sel=MessageBox(NULL,"Are you sure you wish to quit MazeThru?",
                                "U Sure Bro?",MB_YESNO);
        if (sel==IDYES)
        {
            q=true;
            return;
        }
        ShowCursor(FALSE);
    }

    double stheta=sin(dtx*PI180);
    double ctheta=cos(dtx*PI180);
    int nx=x,ny=y;
    if (W||Up||Comma)
    {
        ny+=VELOCITY*stheta;
        nx+=VELOCITY*ctheta;
    }
    if (A||Left)
    {
        ny+=VELOCITY*ctheta;
        nx+=VELOCITY*stheta;
    }
    if (S||Down||O)
    {
        ny-=VELOCITY*stheta;
        nx-=VELOCITY*ctheta;
    }
    if (D||Right||E)
    {
        ny-=VELOCITY*ctheta;
        nx-=VELOCITY*stheta;
    }
    if (LMB&&nred>0)
    {
        LMB=false;
        CrumbDef redCrumb;
        redCrumb.x=x;
        redCrumb.z=y;
        redCrumb.tex=cred;
        crumbs.push_back(redCrumb);
        nred--;
    }
    if (RMB&&ngreen>0)
    {
        RMB=false;
        CrumbDef greenCrumb;
        greenCrumb.x=x;
        greenCrumb.z=y;
        greenCrumb.tex=cgreen;
        crumbs.push_back(greenCrumb);
        ngreen--;
    }
    if (Space&&nblue>0)
    {
        Space=false;
        CrumbDef blueCrumb;
        blueCrumb.x=x;
        blueCrumb.z=y;
        blueCrumb.tex=cblue;
        crumbs.push_back(blueCrumb);
        nblue--;
    }
    if (Ctrl)
        height=PLAYER_HEIGHT_CROUCH;
    else
        height=PLAYER_HEIGHT_STAND;
    //Collision detection:
    //start with start/end:
    if (((end.xi==end.xf)&&(//horizontal wall case
        (x<(end.xi-WALL_WIDTH)&&nx>(end.xi-WALL_WIDTH))||//to the left
        (x>(end.xi+WALL_WIDTH)&&nx<(end.xi+WALL_WIDTH))))||//to the right
        ((end.zi==end.zf)&&(//vertical wall case
        (y<(end.zi-WALL_WIDTH)&&ny>(end.zi-WALL_WIDTH))||//above
        (y>(end.zi+WALL_WIDTH)&&ny<(end.zi+WALL_WIDTH)))))//below
    {
        mazeDimx*=size_factors[level];
        mazeDimy*=size_factors[level++];
        if (level>19)
        {
            int sel=MessageBox(NULL,"OMG! You beat all the levels... do you want"
                           " to play again?","YOU WIN!",MB_YESNO);
            if (sel==IDYES)
            {
                mazeDimx=INIT_W;
                mazeDimy=INIT_H;
                level=0;
                GenMaze(mazeDimx,mazeDimy);
            }
            else
            {
                q=true;
                return;
            }
        }
        else
        {
            GenMaze(mazeDimx,mazeDimy);
            nred=ngreen=nblue=MAX_CRUMBS;
        }
    }
    if (start.xi==start.xf)
    {
        if ((x<(start.xi-WALL_WIDTH)&&nx>(start.xi-WALL_WIDTH))||//head-on-ish
            (x>(start.xi-WALL_WIDTH)&&x<start.xi))//sneaky edge-on case
            nx=start.xi-WALL_WIDTH;
        if ((x>(start.xi+WALL_WIDTH)&&nx<(start.xi+WALL_WIDTH))||//head-on-ish
            (x<(start.xi+WALL_WIDTH)&&x>start.xi))//sneaky edge-on case
            nx=start.xi+WALL_WIDTH;
    }
    if (start.zi==start.zf)
    {
        if ((x<(start.zi-WALL_WIDTH)&&nx>(start.zi-WALL_WIDTH))||//head-on-ish
            (x>(start.zi-WALL_WIDTH)&&x<start.zi))//sneaky edge-on case
            nx=start.zi-WALL_WIDTH;
        if ((x>(start.zi+WALL_WIDTH)&&nx<(start.zi+WALL_WIDTH))||//head-on-ish
            (x<(start.zi+WALL_WIDTH)&&x>start.zi))//sneaky edge-on case
            nx=start.zi+WALL_WIDTH;
    }
    for (int i=0; i<walls.size(); ++i)
    {
        if (walls[i].xi==walls[i].xf)
        {
            if ((x<(walls[i].xi-WALL_WIDTH)&&nx>(walls[i].xi-WALL_WIDTH))||
                (x>(walls[i].xi-WALL_WIDTH)&&x<walls[i].xi))//sneaky edge-on
                nx=walls[i].xi-WALL_WIDTH;
            if ((x>(walls[i].xi+WALL_WIDTH)&&nx<(walls[i].xi+WALL_WIDTH))||
                (x<(walls[i].xi+WALL_WIDTH)&&x>walls[i].xi))//sneaky edge-on
                nx=walls[i].xi+WALL_WIDTH;
        }
        if (walls[i].zi==walls[i].zf)
        {
            if ((x<(walls[i].zi-WALL_WIDTH)&&nx>(walls[i].zi-WALL_WIDTH))||
                (x>(walls[i].zi-WALL_WIDTH)&&x<walls[i].zi))//sneaky edge-on
                nx=walls[i].zi-WALL_WIDTH;
            if ((x>(walls[i].zi+WALL_WIDTH)&&nx<(walls[i].zi+WALL_WIDTH))||
                (x<(walls[i].zi+WALL_WIDTH)&&x>walls[i].zi))//sneaky edge-on
                nx=walls[i].zi+WALL_WIDTH;
        }
    }
    x=nx;y=ny;
    for (int i=0; i<crumbs.size(); ++i)
    {
        if (fabs(x-crumbs[i].x)<CRUMB_DIM&&
            fabs(y-crumbs[i].z)<CRUMB_DIM)
        {
            if (crumbs[i].tex==cred)nred++;
            if (crumbs[i].tex==cblue)nblue++;
            if (crumbs[i].tex==cgreen)ngreen++;
            crumbs.erase(crumbs.begin()+i);
        }
    }
    dtx+=(float)dx*LOOK_FACTOR;
    dty+=(float)dy*LOOK_FACTOR;
    MazeDraw();
    SetCursorPos(winLeft+winWidth/2,winTop+winHeight/2);

}

#endif // MAZE_STEP_H

MazeGen.h:

#ifndef MAZE_GEN_H
#define MAZE_GEN_H
#include <stdlib.h>
#include <time.h>
struct MazeCell
{
    bool left,right,top,bottom;
};
WallDef GENWALL(float a, float b, float c, float d)
{
    WallDef ret;
    ret.xi=a;ret.xf=b;ret.zi=c;ret.zf=d;
    return ret;
}
void GenMaze(int w, int h)
{
    srand(time(NULL));
    std::vector<MazeCell> cells;
    for (int i=0; i<w*h; ++i)
        cells.push_back((MazeCell){true,true,true,true});
    std::vector<int> visited;
    int curr=0;
    int tmp;
    int numVisited=1;
    while (numVisited<cells.size())
    {
        std::vector<int> adjacents;
        if (curr-w>0)
        {
            if (cells[curr-w].left&&
                cells[curr-w].right&&
                cells[curr-w].top&&
                cells[curr-w].bottom)
                adjacents.push_back(curr-w);
        }
        if (curr-1>=0&&curr%w!=0)
        {
            if (cells[curr-1].left&&
                cells[curr-1].right&&
                cells[curr-1].top&&
                cells[curr-1].bottom)
                adjacents.push_back(curr-1);
        }
        if (curr+1<w*h&&(curr+1)%w!=0)
        {
            if (cells[curr+1].left&&
                cells[curr+1].right&&
                cells[curr+1].top&&
                cells[curr+1].bottom)
                adjacents.push_back(curr+1);
        }
        if (curr+w<w*h)
        {
            if (cells[curr+w].left&&
                cells[curr+w].right&&
                cells[curr+w].top&&
                cells[curr+w].bottom)
                adjacents.push_back(curr+1);
        }
        if (adjacents.size()>0)
        {
            tmp=adjacents[rand()%adjacents.size()];
            if (tmp==curr-w)
            {
                cells[tmp].bottom=false;
                cells[curr].top=false;
            }
            if (tmp==curr-1)
            {
                cells[tmp].right=false;
                cells[curr].left=false;
            }
            if (tmp==curr+1)
            {
                cells[tmp].left=false;
                cells[curr].right=false;
            }
            if (tmp==curr+w)
            {
                cells[tmp].top=false;
                cells[curr].bottom=false;
            }
            visited.push_back(curr);
            curr=tmp;
            ++numVisited;
        }
        else
        {
            curr=visited.back();
            visited.pop_back();
        }
    }
    float startloc=(float)((rand()*rand())%h);
    float endloc=(float)((rand()*rand())%h);
    start=GENWALL(0.0f,0.0f,startloc*WALL_LENGTH,(startloc+1.0f)*WALL_LENGTH);
    end=GENWALL(w*WALL_LENGTH,w*WALL_LENGTH,
            endloc*WALL_LENGTH,(endloc+1.0f)*WALL_LENGTH);
    walls.clear();
    //generate the necessary horizontal walls:
    for (int yy=0; yy<h; ++yy)
    {
        for (int xx=0; xx<w; ++xx)
        {
            if (cells[yy*w+xx].top)
            {
                walls.push_back(GENWALL((float)xx*WALL_LENGTH,
                                          (float)(xx+1)*WALL_LENGTH,
                                          (float)yy*WALL_LENGTH,
                                          (float)yy*WALL_LENGTH));
            }
        }
    }
    //generate the necessary vertical walls... special cases for start,end
    for (int yy=0; yy<h; ++yy)
    {
        for (int xx=0; xx<w; ++xx)
        {
            if (cells[yy*w+xx].left)
            {
                if ((float)yy!=startloc&&(float)yy!=endloc)
                {
                    walls.push_back(GENWALL((float)xx*WALL_LENGTH,
                                              (float)xx*WALL_LENGTH,
                                              (float)yy*WALL_LENGTH,
                                              (float)(yy+1)*WALL_LENGTH));
                }
            }
        }
    }
    //todo, far right, and bottom walls!
    for (int xx=0; xx<w; ++xx)
    {
        walls.push_back(GENWALL((float)xx*WALL_LENGTH,
                                (float)(xx+1)*WALL_LENGTH,
                                (float)h*WALL_LENGTH,
                                (float)h*WALL_LENGTH));
    }
    for (int yy=0; yy<h; ++yy)
    {
        walls.push_back(GENWALL((float)w*WALL_LENGTH,
                                (float)w*WALL_LENGTH,
                                (float)yy*WALL_LENGTH,
                                (float)(yy+1)*WALL_LENGTH));
    }
    x=WALL_LENGTH/2.0f;
    y=WALL_LENGTH/2.0f;
}

#endif // MAZE_GEN_H

Note that I am aware that the style (lots of globals, no classes, etc) is less than ideal for debugging, I only had 48 hrs to make this, I am working on converting the code to a more friendly format, but it will take awhile (the game jam has put me a bit behind on my school work, and coop season is just around the corner so I have to work on applying to jobs too)

The only thing that really stands out initially is the following:

while (!bQuit)
105.    {
106.        /* check for messages */
107.        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
108.        {
109.            /* handle or dispatch messages */
110.            if (msg.message == WM_QUIT)
111.            {
112.                bQuit = TRUE;
113.            }
114.            else
115.            {
116.                TranslateMessage(&msg);
117.                DispatchMessage(&msg);
118.            }
119.        }
120.        else
121.        {
122.            MazeStep(bQuit);
123.            SwapBuffers(hDC);
124.        }
125.    }

The else statement in this loop means you aren't drawing and performing animation/physics every iteration through the loop, only the times when you don't have a message from the OS.

It would probably be worth moving that out of the else clause so that it's executed every iteration regardless. I have a suspicion that you are drawing only once, when you set your clear colour.

Make that change and see if it fixes it, if not, I won't have chance to step through your code myself until about 19:30GMT

Ok, I tried removing the else, and calling the mazeStep from both the if and the else, neither worked... any other ideas?

Unfortunately I've been so busy I haven't had time to look into this. Do you already have a solution?
If you do, please post it :)
If not, I haven't forgotten you, just I have to prioritise personal work and life and recently this has taken up a lot of my free time.

This article has been dead for over six months. Start a new discussion instead.