• Advertisement

Archived

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

simple code problem

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

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;
}
 

Share this post


Link to post
Share on other sites
Advertisement
when u use gluPerspective,pls locate the position of object properly first.

jerry2
Programming,make a whole new world.

Share this post


Link to post
Share on other sites
the point is behind your camera, try:
glVertex3f(0.0f, 0.0f, -2.0f);

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement