[gameprogrammer] Re: glut problems
- From: "Bob Kozdemba" <bkozdemba@xxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Fri, 20 Apr 2007 10:00:12 -0500
A couple issues:
Call glutInitDisplayMode() before glutCreateWindow(). Also add
GLUT_DEPTH since you have enabled depth testing.
The triangle is being clipped. Change glTranslatef(0.0f,0.0f,-6.5f) to
glTranslatef(0.0f,0.0f,-0.5f);
Then you should see your triangle - it worked for me.
Bob
On 4/20/07, Yasser Gonzalez <yassergs@xxxxxxxxxxxxxxx> wrote:
Some body colud tell me what happends with this code. I don't see the
triangle on the screen:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <gl/glut.h>
void init(GLvoid)
{
glClearColor(1.0f,0.0f,1.0f,0.0f);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(80.0f,(float)w/(float)h,1.0f,5000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-6.5f);
glBegin(GL_TRIANGLES);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f,0.0f);
glVertex3f(1.0f,-1.0f,0.0f);
glEnd();
glutSwapBuffers();
}
void idle(void)
{
display();
}
void keyPressed(unsigned char k, int x,int y)
{
switch(k)
{
case 27:
exit(0);
break;
}
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitWindowPosition(5,5);
glutInitWindowSize(400,400);
glutCreateWindow("Ejemplo 2 de GLUT");
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
init();
glutDisplayFunc(display);
glutIdleFunc(idle);
glutKeyboardFunc(keyPressed);
glutMainLoop();
return 1;
}
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- References:
- [gameprogrammer] glut problems
- From: Yasser Gonzalez
Other related posts:
- » [gameprogrammer] glut problems
- » [gameprogrammer] Re: glut problems
Some body colud tell me what happends with this code. I don't see the
triangle on the screen:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <gl/glut.h>
void init(GLvoid)
{
glClearColor(1.0f,0.0f,1.0f,0.0f);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(80.0f,(float)w/(float)h,1.0f,5000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-6.5f);
glBegin(GL_TRIANGLES);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f,0.0f);
glVertex3f(1.0f,-1.0f,0.0f);
glEnd();
glutSwapBuffers();
}
void idle(void)
{
display();
}
void keyPressed(unsigned char k, int x,int y)
{
switch(k)
{
case 27:
exit(0);
break;
}
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitWindowPosition(5,5);
glutInitWindowSize(400,400);
glutCreateWindow("Ejemplo 2 de GLUT");
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
init();
glutDisplayFunc(display);
glutIdleFunc(idle);
glutKeyboardFunc(keyPressed);
glutMainLoop();
return 1;
}
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- [gameprogrammer] glut problems
- From: Yasser Gonzalez