• Announcements

Archived

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

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 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 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 on other sites
good call on the ortho, i''ll fix that.

Share on other sites
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)

• Forum Statistics

• Total Topics
627701
• Total Posts
2978705
• Similar Content

• A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

-What I'm using:
C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.
-Questions
Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• 21
• 14
• 12
• 10
• 12