Results 1 to 7 of 7

Thread: Draw a square?

  1. #1
    Member Contributor
    Join Date
    Apr 2011
    Location
    Barcelona, Catalunya
    Posts
    55

    Draw a square?

    Hi, I try to draw a square but I have the problem which can be see and the images. Can someone explain me why?

    I use GL_QUADS.

    Thanks

  2. #2
    Senior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    Re: Draw a square?

    It looks like you are drawing the vertices in the wrong order. You need to keep an orientation. Can you post your draw code here?

  3. #3
    Member Contributor
    Join Date
    Apr 2011
    Location
    Barcelona, Catalunya
    Posts
    55

    Re: Draw a square?

    The coords:

    GLfloat a[]={
    0.0f,0.0f,0.0f,0.0f,
    0.0f,1.0f,0.0f,0.0f,
    0.0f,0.0f,1.0f,0.0f,
    0.0f,1.0f,1.0f,0.0f
    };

  4. #4
    Senior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    Re: Draw a square?

    As I said, it is in the wrong order.

    Code :
    GLfloat a[]={
    0.0f,0.0f,0.0f,0.0f, 
    0.0f,1.0f,0.0f,0.0f,
    0.0f,1.0f,1.0f,0.0f   
    0.0f,0.0f,1.0f,0.0f,
    };
     
    // change coord 3 with 4.

    BTW, why homogeneous coords are set to 0.0f? It shouldn't be 1.0f?

  5. #5
    Member Contributor
    Join Date
    Apr 2011
    Location
    Barcelona, Catalunya
    Posts
    55

    Re: Draw a square?

    Ok, it works! Thank you!

    I try with 0.0f and 1.0f and I don't see any difference, so I prefer with 0.0f because it's easier to read.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    Re: Draw a square?

    It is odd. Using 0.0 as the homogeous coordinates gives you a vector instead of a point. Maybe, when you are drawing, you are ignoring the fourth coordinate. In order to have project points on screen, OpenGL divides x,y and z by the w value, if it is different from 0.

  7. #7
    Member Contributor
    Join Date
    Apr 2011
    Location
    Barcelona, Catalunya
    Posts
    55

    Re: Draw a square?

    I see,

    In my code I write:
    glVertexPointer(3,GL_FLOAT,4*sizeof(GL_FLOAT),0);
    It has been copied from a code on Internet

    Now I put glVertexPointer(4,GL_FLOAT,4*sizeof(GL_FLOAT),0);
    with the w value to 1.0f.

    Thanks

Similar Threads

  1. need help to draw 3D square mesh
    By badass in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-23-2010, 06:07 AM
  2. draw square with 2 vertices given possible?
    By Numberator in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-23-2010, 06:50 PM
  3. Square texture doesnt fit to square plane.
    By tiregarfio in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-03-2006, 03:09 AM
  4. clicking a square mesh and printing the value of the square
    By iris_raj in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-21-2004, 10:29 PM
  5. Q: how to draw a 2D square in a 3D space?
    By jyoung77 in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 02-06-2001, 10:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean