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>

#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()
{
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();

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

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 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]

Create an account

Register a new account

• Forum Statistics

• Total Topics
628305
• Total Posts
2981967

• 9
• 13
• 11
• 12
• 11