Jump to content
  • Advertisement
Sign in to follow this  
Drunken_Monkey

Need some help getting SDL/OGL set up

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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!