Sign in to follow this  
Drunken_Monkey

Need some help getting SDL/OGL set up

Recommended Posts

It's been roughly a year since I've used C++. Now that the semester's over, I need something to keep myself occupied. I'm trying to get the base code for SDL and OpenGL set up, but something isn't working correctly:
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <quaternion.h>
#include <OBJLoader.h>

#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")

#include <string>

using namespace std;

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 32

quaternion rotation;

void initSDL(string name)
{
	SDL_Init(SDL_INIT_EVERYTHING);
	SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL);
	SDL_WM_SetCaption(name.c_str(), NULL);
}

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

bool getInput()
{
	static SDL_Event input;

	while(SDL_PollEvent(&input))
	{
		if(input.type == SDL_QUIT)
			return false;
	}

	if(input.key.keysym.sym == SDLK_ESCAPE)
		return false;

	if(input.key.keysym.sym == SDLK_RIGHT)
		rotation.rotate(.01, 0, 1, 0);

return true;
}

int main(int argc, char** argv)
{
	initSDL("Quaternion Test");
	initGL();

	OBJLoader cube("C:/cube.obj");

	while(getInput())
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glLoadIdentity();
		gluLookAt(0, 0, 0, 20, 20, 20, 0, 1, 0);

		cube.render();

		SDL_GL_SwapBuffers();
	}

	SDL_Quit();

	return 0;
}

I know my OBJLoader class is working and cube.obj is correct. Here's what I get: Does anyone know what's wrong?

Share this post


Link to post
Share on other sites
Edit: Just noticed, your not setting up the projection matrix for the desired perspective, or the model view matrix when your rendering. Maybe thats why it doesn't seem to look right?

You might want to look at the first few lessons here to get you up to speed again.

Whats wrong with it? What is the app supposed to do/show?
I cant see anything wrong with the code you provided. From the looks of things, the white area of the screen shot is the cube mesh?

Try rendering the view in wireframe, I found that helped alot when I developed my wavefront obj mesh loader. If the mesh does render properly, the only other thing I can think of is maybe it's a problem with your quaternion object?


[Edited by - cNoob on May 12, 2008 5:35:18 PM]

Share this post


Link to post
Share on other sites

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