Jump to content
  • Advertisement

Archived

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

CharSoft

glut problem

This topic is 5386 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

whenever i use GLUT, i cant seem to make objects rotate. anyone have any same experiences and/or fixes? thanks, and if needed, i can post code.

Share this post


Link to post
Share on other sites
Advertisement
#include <windows.h>
#include <gl\glut.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

void initGL();
void display();

GLfloat trirot;

int main(int argc, char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,200);
glutCreateWindow("Neo3D");
initGL();
glutDisplayFunc(display);
glutMainLoop();

return 0;
}

void initGL()
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)250/(GLfloat)250,0.1f,100.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(-1.5f,0.0f,-6.0f);
glRotatef(trirot,0.0f,1.0f,0.0f);
glBegin(GL_TRIANGLES);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
trirot += 0.5f;
glutSwapBuffers();
}

Share this post


Link to post
Share on other sites
Fixed it (among other random changes I made but I''m too lazy to correct back to what you had).

#include <GL/glut.h>

void initGL();
void reshape(int, int);
void display();

GLfloat trirot = 0.0f;

int main(int argc, char *argv[])
{
glutInit(&argc,argv);

glutInitWindowSize(400, 400);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutCreateWindow("Neo3D");

initGL();

glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();

return 0;
}

void initGL()
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}

void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (float)width/(float)height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();
glTranslatef(0.0f, 0.0f, -6.0f);
glRotatef(trirot, 0.0f, 1.0f, 0.0f);

glBegin(GL_TRIANGLES);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();

trirot += 0.5f;
glutSwapBuffers();
}


The problems fixed: you had never set an idle function (so it''d only redraw if it had to), you had no reshape function (not really important, but it made the window un-resizable), you forgot to set the matrix mode back to the modelview after you were done messing with the projection, and you including headers that were not necessary (the GL should be capitalized, no need for windows.h, no need for GLaux, GL and GLU are handled by GLUT).

Share this post


Link to post
Share on other sites
thanks! that ALSO explains why glLoadIdentity(); made it not render any more... big big BIG thanks! wish there was a rating system on here...

and the reason glaux was included was because im implementing texturing soon.

Share this post


Link to post
Share on other sites
crap, now its complaining about 45 C:\DEV-CPP\include\gl\glut.h
redeclaration of C++ built-in type `wchar_t'


i didnt compile your code last night, so i did now, and i get this, even after fixing the include's backslash...

LATER: well, i fixed it by including windows.h before glut.h. i have no clue why, but it must like windows.h...

[edited by - charsoft on September 22, 2003 9:45:26 AM]

Share this post


Link to post
Share on other sites

  • 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!