Sign in to follow this  

(Solved) My OpenGL perspective is screwed up...

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

#include <sdl/sdl.h>
#include <sdl/sdl_opengl.h>
#include "C:/objloader.h"
#pragma comment(lib, "sdl.lib")
#pragma comment(lib, "sdlmain.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")

SDL_Event keyboard;
OBJLoader cube;

int main(int argc, char* argv[])
{
	cube.load("C:/cube.obj");
	bool quit = false;
	if(SDL_Init(SDL_INIT_EVERYTHING) < 0) return 0;
	if(SDL_SetVideoMode(640, 480, 32, SDL_OPENGL) == NULL) return 0;

	glViewport(0, 0, 640, 480);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45, 640 / 480, .1, 1000);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glShadeModel(GL_SMOOTH);
	glClearColor(0, 0, 0, 0);
	glClearDepth(1);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	float lightPos[] = {0, 3, -5, 1};
	float lightCol[] = {1, 1, 1};

	SDL_WM_SetCaption("Quaternions", NULL);

	while(!quit)
	{
		while(SDL_PollEvent(&keyboard))
		{
			if(keyboard.type == SDL_QUIT) quit = true;
		}

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		glLoadIdentity();
		glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
		glLightfv(GL_LIGHT0, GL_AMBIENT, lightCol);
		glLightfv(GL_LIGHT0, GL_SPECULAR, lightCol);
		
		glTranslatef(0, 0, -9);
		cube.render();
		SDL_GL_SwapBuffers();
	}
	return 0;
}


The OBJLoader object in my code loads a cube, but when I render it using this short program, it shows up like this: It's rectangle! O.o Where did I screw up? [Edited by - Drunken_Monkey on June 2, 2007 8:19:54 PM]

Share this post


Link to post
Share on other sites
In this line...
gluPerspective(45, 640 / 480, .1, 1000);
Your "640 / 480" is an integer division and will result in an integer. Use floats instead to get the correct aspect ratio.

Regards,
ViLiO

Share this post


Link to post
Share on other sites

This topic is 3849 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this