Archived

This topic is now archived and is closed to further replies.

Muksitul

glut and lesson 23

Recommended Posts

HI Im an OpenGL newbie ,but Iv been onto this site long before I started coding in gl. Anyway I was just wondering if anyone has made the tutorial 10 and 23 using glut and OpenGL and not DirectX for input.If any of you have made it please let me know .Since nehe is more of an OpenGL site I would have preferred if those two tutorials were made using glut and OpenGL and no DirectX. Thank You Muksitul

Share this post


Link to post
Share on other sites
Let''s see what I can do real quick... Most of the code will be the same. I''ll just comment out sections that are, and that''ll make it easier to look at...


  
// Include Files look okay


// Get rid of HDC, HGLRC, HWND, and HINSTANCE types. The rest of the global constants should be kept.


// Keep the typedef''s


// Get rid of the Function Prototype for "WndProc"


// readstr() No changes

// SetupWorld() No changes

// LoadBMP() No changes

// LoadGLTextures() No changes

// ReSizeGLScene() No changes

// InitGL() No changes

// DrawGLScene() No changes


// Get rid of KillGLWindow()


void KeyboardGL(unsigned char key, int x, int y)
{
if(key == ''B'' || key == ''b'')
{
blend = !blend;
if(!blend)
{
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}
else
{
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
}
}
if (key == ''F'' || key == ''f'')
{
filter += 1;
if(filter > 2) filter = 0;
}
}

void KeyboardSpecialGL(int key, int x, int y)
{
if(key == GLUT_KEY_LEFT)
{
heading += 1.0f;
yrot = heading;
}
else if(key == GLUT_KEY_RIGHT)
{
heading -= 1.0f;
yrot = heading;
}
else if(key == GLUT_KEY_DOWN)
{
xpos += (float)sin(heading*piover180) * 0.05f;
zpos += (float)cos(heading*piover180) * 0.05f;
if (walkbiasangle <= 1.0f) walkbiasangle = 359.0f;
else walkbiasangle-= 10;
walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
}
else if(key == GLUT_KEY_UP)
{
xpos -= (float)sin(heading*piover180) * 0.05f;
zpos -= (float)cos(heading*piover180) * 0.05f;
if (walkbiasangle >= 359.0f)
{
walkbiasangle = 0.0f;
}
else
{
walkbiasangle+= 10;
}
walkbias = (float)sin(walkbiasangle * piover180)/20.0f;

}
else if(key == GLUT_KEY_PAGE_UP)
{
z -= 0.02f;
lookupdown -= 1.0f;
}
else if(key == GLUT_KEY_PAGE_DOWN
{
z += 0.02f;
lookupdown += 1.0f;
}
}

void CreateGLWindow(void* args)
{
glutInit(new int(1), (char**)args);
// change the "1" to however many command-line parameters you type in after the executable + 1.

glutInitWindowSize(640, 480);
glutInitWindowPosition(0, 0);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow("Title of Window Here")
if(!glInit()) return;

glutKeyboardFunc(KeyboardGL);
glutSpecialFunc(KeyboardSpecialGL);
glutReshapeFunc(ReSizeGLScene);
glutDisplayFunc(DrawGLScene);
glutMainLoop();
}



Note: In my rush to make this, I didn''t handle fullscreen mode (since I hate fullscreen mode and never use it and was too lazy to look it up). However, you can make fullscreen windows. If you head over to www.opengl.org and look up the GLUT API, it should tell you how to do that. I also didn''t handle button repetition using NeHe''s boolean button arrays, because I don''t know how to check to see if the key has been let go. Other than that (*crosses fingers*) it should all be here... I hope...

I really hope this works... ^^0

~ Dragonus

Share this post


Link to post
Share on other sites
Dragonus code will work but the program will run badly. The problem is that the keyboard functions will only be called then the OS sends a new key event. Unfortunate is this a common misstake in GLUT programs and I think that the ports of lesson 10 and 23 does so.

The right way is to have variables for the keys and setting them in the keyboard and keyboardup functions. For a tutorial look at
http://www.fatech.com/tech/opengl/glut/index.php3?5

It is not difficult and you can change the GLUT (IRIX) ports if you want to.

Share this post


Link to post
Share on other sites