Jump to content
  • Advertisement
Sign in to follow this  
pavel989

best way to set up window in opengl

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

ive seen a few ways of doing that. and its pretty typical; set window size x by y, make a matrix. but thats there i start having issues. im confused as to how opengl knows where the x coordinate of a vector is.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by pavel989
im confused as to how opengl knows where the x coordinate of a vector is.


Can you elaborate this question?
I don't understand it.

Share this post


Link to post
Share on other sites
That made 0% to me. Please give some details so we know what you are talking about and make sure you know what you are talking about.

Share this post


Link to post
Share on other sites
I have no idea what this dude just said but I am going to answer the topic's title.

I personally use a statically linked version of GLFW to open a window. There are other solutions such as SDL (I think), GLUT, Win32 API (along with the X Windows System equivalent if you cross platform), and MFC. All of the ones I listed will let you open a window with varying amounts of effort.

And OpenGL transforms all of its vertices (why is Firefox telling me I spelled vertices wrong?) with a couple of matrices; ModelView, Projection, and some others I forgot.

[Edit]
Misspelled a word (not vertices)

[Edited by - KodeNerd on July 20, 2008 9:43:28 AM]

Share this post


Link to post
Share on other sites
I'm a fan of using SDL to setup the Window. Nice and tidy cross-platform way of setting it up.


Vertices. ...Indeed, Firefox can't spell.

Share this post


Link to post
Share on other sites
sorry posted late into the night and had no idea how to explain what i meant. my bad.
so here are the examples i was talking about. they're taken from a few tutorials:


void init (void) {
glClearColor(0.0, 0.0, 0.0, 0.0);
glColor3f(0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 10.0, 0.0, 10.0, 0.0, 10.0);
}


void reshape(int w, int h) {
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}


void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}

in specific, im confused about matrixmode, viewport, and ortho. Like y are they doing it differently? or are they really not?

Share this post


Link to post
Share on other sites
I suggest reading the specifications for those functions, google them.

In general, glMatrixMode(whatever) sets the current opengl matrix to receive operations to "whatever". The most common 2 are GL_PROJECTION and GL_MODELVIEW.

GL_PROJECTION in general is going to govern how the object looks (2d vs 3d) while GL_MODELVIEW determines where the object is in the world (camera position, etc.)

glOrtho and gluPerspective are supposed to be called after switching to GL_PROJECTION and set up an orthographic or perspective projection matrix. The big difference is the former makes things look flat and 2d while the latter makes them 3d. The parameters to the functions adjust the look.

glViewport determines where the edges of the rendering area should be in the current opengl context. In general, if you set up a single window with the context taking up the whole thing (SDL, glut, etc.) the viewport will be the whole screen unless you want some kind of split screen gameplay. In this case the arguments are just 0,0,width,height with width,height being the dimension of the screen.

Again, the best way to learn specifics about these things is the look up the documentation for each function. Google is god.

Share this post


Link to post
Share on other sites
i looked them up and it still confused me, so i came here. ok so like, you can establish everything all at once? you have to separately like set up how the object looks and then the position?

Share this post


Link to post
Share on other sites
Quote:
Original post by pavel989
i looked them up and it still confused me, so i came here. ok so like, you can establish everything all at once? you have to separately like set up how the object looks and then the position?
Your questions are a little hard to answer due to their lack of specificity. For example, what does 'set up how the object looks' mean in technical terms? Are you talking about the type of projection used?

Anyway, it sounds to me like you need to study up on the OpenGL pipeline a bit (and graphics pipelines in general). Once you have a better idea of how the pipeline works, the OpenGL functions you're asking about will seem less mysterious.

Share this post


Link to post
Share on other sites
Quote:
Original post by pavel989
in specific, im confused about matrixmode, viewport, and ortho. Like y are they doing it differently? or are they really not?

I don't understand. Where is y treated differently ? Both coordinates (x,y) are treated symmetrically during the world to screenspace transformation.

Quote:
Original post by pavel989
i looked them up and it still confused me, so i came here. ok so like, you can establish everything all at once? you have to separately like set up how the object looks and then the position?

I'm still not sure what you mean, but I assume you're asking why you have to call several different commands with essentially the same parameters ? Well, OpenGL is first and foremost a 3D API. And while some functions like glOrtho and glViewport might require the same values in 2D, they're defining something very distinct in the rendering pipeline, and will be entirely different when doing 3D. OpenGL was never really designed to do something as simple as screenspace 2D, that's why setting it up is a little more complicated than if you use a purely 2D graphics library.

Quote:

so here are the examples i was talking about. they're taken from a few tutorials:

All these examples set up very different projection and transformation modes. They are not interchangeable. The first two set up an orthographic projection of two different dimensions and the third sets up a perspective projection (this is for 3D rendering, you don't want this for 2D).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!