Archived

This topic is now archived and is closed to further replies.

Red_Riot

OpenGL My First Square? Init OpenGL Question: (noobie)

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites