simple code problem

Started by
2 comments, last by flame_warrior 22 years, 2 months ago
Hi, I am trying to learn opengl and I tried to do a simple pixel on screen using gluPerspective and I am not getting anything on screen. I am assuming something to do with gluLookAt. What am I doing wrong ? Thanks for the help.

#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>

void Init()
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glShadeModel(GL_FLAT);
	
	
}

void Mountain()
{
	glColor3f(1.0f, 1.0f, 1.0f);
	glBegin(GL_POINTS);
		glVertex3f(0.0f, 0.0f, 1.0f);
	glEnd();
}

void Display()
{
	glClear(GL_COLOR_BUFFER_BIT );
	glPushMatrix();
	Mountain();
	glPopMatrix();

	glFlush();
}

void Reshape(int w, int h)
{
	glViewport(0, 0, (GLsizei)w, (GLsizei)h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f, (GLfloat)w/(GLfloat)h, 1.0f, 100.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
}

int main()
{
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(500, 500);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("Mountain");
	Init();
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutMainLoop();

	return 0;
}
 
Hello from my world
Advertisement
when u use gluPerspective,pls locate the position of object properly first.

jerry2
Programming,make a whole new world.
jerry2The God creates the world, the world creates the nature,the nature creates human. Human create...Everything.
the point is behind your camera, try:
glVertex3f(0.0f, 0.0f, -2.0f);
------------------------------------------------------CCP is fascistic, they even banned www.sourceforge.net
quote:Original post by ed9er
the point is behind your camera, try:
glVertex3f(0.0f, 0.0f, -2.0f);


Hi,

That works.

I was assuming that as gluPerspective has znear and zfar as 1.0f and 100.0f then for moving further I would have to increase z in the positive z-axis. Now I realize its the negative z-axis value which I should increasing.

Thank you
Hello from my world

This topic is closed to new replies.

Advertisement