My First Square? Init OpenGL Question: (noobie)
I have a question for anyone who has the time, thanks in advance:
I''m trying to get my first square in OpenGL up and running under SDL. I know that OpenGL is working fine because I can clear the screen to any color I wish, or a changing color as well. My problem, however, lies in that a polygon that I''ve sent down the line doesn''t seem to want to apear. I''m hoping that one of the masterminds here knows, perchance what''s wrong. I''m using a simple 640x480 resolution for testing purposes. I''ve been hacking on this for about 2 days, trying to figure out what''s screwy.
attn to the Init OpenGL part I believe, perchance there''s an error with perspective?
#include "shards.h"
shards::shards()
{
}
shards::~shards()
{
SDL_Quit();
}
bool shards::setup()
{
//SDL SETUP
int bitpp;
const SDL_VideoInfo* info=NULL;
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
SDL_Quit();
return false;
}
info = SDL_GetVideoInfo();
bitpp = info->vfmt->BitsPerPixel;
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
if (!SDL_SetVideoMode(640,480,bitpp,SDL_OPENGL|SDL_FULLSCREEN))
{
SDL_Quit();
return false;
}
//init OpenGL
glViewport(0,0,640,480);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)640/(GLfloat)480,1.0f,150.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return true;
}
void shards::draw()
{
glClearColor(0, 0, 0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25,0.25,0.0);
glVertex3f(0.75,0.25,0.0);
glVertex3f(0.75,0.75,0.0);
glVertex3f(0.25,0.75,0.0);
glEnd();
glFlush();
SDL_GL_SwapBuffers();
}
bool shards::input()
{
SDL_Event event;
while (SDL_PollEvent ( &event ) )
{
switch ( event.type )
{
case SDL_KEYDOWN:
printf( "Key press detected\n" );
return false;
break;
case SDL_KEYUP:
printf( "Key release detected\n" );
return false;
break;
default:
break;
}
}
return true;
}
Thanks again in advance.
The quickest way to get this to work is to set the third parameter of glVertex3f to something >= 1.0f. I can''t explain why this works, though.
Best of luck,
ZE.
Best of luck,
ZE.
i dun have a solution for ur problem, for now, but just wanted to bring up something... u initialized a perspective projection at first, but every iteration of ur draw function explicitly sets to ortho projection before rendering. y not just set it to ortho from the start?
yeah, you gotta set the stuff to apear like -6.0f into the scene, so that you can see it (cuz the camera is at 0,0,0)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement