Jump to content
  • Advertisement

Archived

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

MichaelNolan

OpenGL A new too OpenGL

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

Hi, Why does OpenGL draw a triangle across 1/4 of the buffer? I just use this code.
  
    glBegin(GL_TRIANGLES);
        glVertex3f(0.0f,0.0f,1.0f);
        glVertex3f(1.0f,0.0f,1.0f);
        glVertex3f(1.0f,1.0f,1.0f);
    glEnd();
  
Best Regards, Michael

Share this post


Link to post
Share on other sites
Advertisement
Let me see if I can tackle this...

You are wondering why you see something like this:


.........
....*....
....**...
....***..
.........


when you wanted to see something like this:

.........
....*....
...***...
..*****..
.........


Well, openGL plotted exactly what you gave it.

Change your code from

glBegin(GL_TRIANGLES);
glVertex3f(0.0f,0.0f,1.0f);
glVertex3f(1.0f,0.0f,1.0f);
glVertex3f(1.0f,1.0f,1.0f);
glEnd();


to

glBegin(GL_TRIANGLES);
glVertex3f(-1.0f,0.0f,1.0f);
glVertex3f(1.0f,0.0f,1.0f);
glVertex3f(0.0f,1.0f,1.0f);
glEnd();

Share this post


Link to post
Share on other sites
Hey,
I see someting like this.
.....*....
.....***..
.....*****
..........
..........
When i use that code. I want to see a triangle the size of a pixel. I typed:
glBegin(GL_TRIANGLES);
glVertex3f(0.0f,0.0f,1.0f);
glVertex3f(1.0f,0.0f,1.0f);
glVertex3f(1.0f,1.0f,1.0f);
glEnd();
I would expect to see this.
..........
..........
....*.....
..........
..........
And if i did want to see what i did, i would type:
glBegin(GL_TRIANGLES);
glVertex3f(0.0f,0.0f,1.0f);
glVertex3f(width,0.0f,1.0f);
glVertex3f(width,height,1.0f);
glEnd();

I hope this helped to clear-up what i was asking.

Share this post


Link to post
Share on other sites
So you want the units of x, y in the vertex position to be one pixel each?

You need to use an orthographic projection instead of a persective one. Use
gluOrtho2D(-windowWidth/2, -windowHeight/2, windowWidth/2, windowHeight/2);

http://users.ox.ac.uk/~univ1234

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!