Jump to content
  • Advertisement
Sign in to follow this  

Program doesn't run? o_O

This topic is 4415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was trying to fix error I had myself, and now it doesn't do anything. When I run the program, nothing shows on the screen, no OpenGL window, nothing... Idk why... code:
[source lang=cpp]
#include <GL/openglut.h> 
#include "camera.cpp"
#include <iostream.h>
#include <fstream.h>
#include <math.h>
#include "model.h"

CCamera Camera;
CModel Model;

void renderScene() 
{
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glLoadIdentity();
     Camera.Render();
     Model.RenderModel(0.0f,0.0f,0.0f);
     glutSwapBuffers();
     glFlush();
}

void changeSize(int w, int h) 
{
     if (h == 0)
          h = 1;

     float ratio = 1.0* w / h;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(0, 0, w, h);
    gluPerspective(45,ratio,1,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
gluLookAt(0.0,0.0,0.0, 
      0.0,0.0,-1.0,
  0.0f,1.0f,0.0f);
}

void processNormalKeys(unsigned char key, int x, int y) 
{
   if (key == 27) 
       exit(0);
}

void processSpecialKeys(int key, int x, int y) 
{
    switch (key) {
        case GLUT_KEY_LEFT : 
             Camera.StrafeRight(0.5f);
    renderScene();            break;
        case GLUT_KEY_RIGHT : 
             Camera.StrafeRight(-0.5f);
    renderScene();            break;
        case GLUT_KEY_UP : 
             Camera.MoveForward(-0.5f);
    renderScene();            break;
        case GLUT_KEY_DOWN : 
             Camera.MoveForward(0.5f);
    renderScene();            break;
        case GLUT_KEY_F2 : 
             Camera.RotateZ(1.0f);
    renderScene();            break;
        case GLUT_KEY_F1 : 
             Camera.RotateZ(-1.0f);
    renderScene();            break;
        case GLUT_KEY_F3 : 
             Camera.RotateX(1.0f);
    renderScene();            break;
        case GLUT_KEY_F4 : 
             Camera.RotateX(-1.0f);
    renderScene();            break;
        case GLUT_KEY_F5 : 
             Camera.MoveUpward(1.0f);
    renderScene();            break;
        case GLUT_KEY_F6 : 
             Camera.MoveUpward(-1.0f);
    renderScene();            break;
    }
}

int main(int argc, char **argv) 
{
     glutInit(&argc, argv);
     glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
     glutInitWindowPosition(100,100);
     glutInitWindowSize(320,320);
     glutCreateWindow("ROFL");
     glutDisplayFunc(renderScene);
     glutIdleFunc(renderScene);
     glutReshapeFunc(changeSize);
     glutKeyboardFunc(processNormalKeys);
     glutSpecialFunc(processSpecialKeys);
     glEnable(GL_DEPTH_TEST);
     glDepthMask(GL_TRUE);
     glDepthFunc(GL_LEQUAL);
     Camera.MoveForward(5);
     glShadeModel(GL_SMOOTH);
     glutMainLoop();   
}

Share this post


Link to post
Share on other sites
Advertisement
If you're running in Windows, you can change the end of main() to this:

.
.
.
glutMainLoop();

MessageBox(0,"end",0,0);
}

Compile and start the program. If the message doesn't appear immediately, there's something with the main loop. Well, if it appears, then you should look for a GLUT tutorial!

Share this post


Link to post
Share on other sites
YES YES! I figured it out. Thank you AndiDog. I put message box at beginning of main() and message box didn't shown. So I figured out something makes program stuck in constructor of CModel class. I looked at it and... omg... I found that I reserve memory for array of unset variable (declared only)... that was crashing the program. Now it works perfect!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!