Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:48:08+00:00 2026-06-14T14:48:08+00:00

I am trying to draw a rectangle with 4 lines (left one). But no

  • 0

I am trying to draw a rectangle with 4 lines (left one). But no matter how I draw (strip, loop, plain lines) the result is the right side one – it is missing pixels at the corners.

|||||||||||     ||||||||||
|         |    |          |
|         |    |          |
|||||||||||     ||||||||||

Is there a way to get the left hand side result?

EDIT

Can’t post code since it depends a lot on the underlying framework, but all draw calls are nothing more than glDrawElements with index buffer pointing to 4 vertices, no alpha tests.

After fiddling with coordinates as suggested arrived at this interesting result (iOS simulator):

sample

Notice only upper left corner is missing pixels for some rectangles…
All rectangles are drawn in GL_LINES mode within single draw elements call. No other things are drawn.

EDIT 2

OpenGL FAQ question 14.100 states that

OpenGL doesn’t provide a mechanism to cleanly join lines that share common vertices nor to cleanly cap the endpoints.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:48:09+00:00Added an answer on June 14, 2026 at 2:48 pm

    Shift your coordinate frame a bit so your lines fall on pixel centers:

    rect

    #include <GL/glut.h>
    
    void display()
    {
        glClear( GL_COLOR_BUFFER_BIT );
    
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        double w = glutGet( GLUT_WINDOW_WIDTH );
        double h = glutGet( GLUT_WINDOW_HEIGHT );
        glOrtho( 0, w, 0, h, -1, 1);
    
        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();
    
        // important
        glTranslatef( 0.5, 0.5, 0 );
    
        float offset = 40;
        glColor3ub( 255, 0, 0 );
        glBegin(GL_LINE_LOOP);
        glVertex2f( 0+offset, 0+offset );
        glVertex2f( 0+offset, h-offset );
        glVertex2f( w-offset, h-offset );
        glVertex2f( w-offset, 0+offset );
        glEnd();
    
        glutSwapBuffers();
    }
    
    int main( int argc, char **argv )
    {
        glutInit( &argc, argv );
        glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
        glutInitWindowSize( 320,240 );
        glutCreateWindow( "Rect" );
        glutDisplayFunc( display );
        glutMainLoop();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to draw a simple rectangle in my iOS cocos2d game, but
i am trying to draw a rectangle when i press mouse left button and
I am trying to draw some basic graphics primitives(line, rectangle etc.) using GDI+ apis
I am simply trying to draw a rectangle inside of a panel using flex4.
I'm new with OpenGLES and I was trying to draw a rectangle with alpha
I'm trying to draw an open rectangle using a Polygon: int[] xPoints = {1,1,3,3};
I am trying to just draw a Rectangle on a PictureBox that is on
I am trying to draw a red rectangle on my HTML5 canvas. Here is
I'm trying to draw a semi-transparent rectangle on top of an image to act
I'm trying to draw 10 rectangles, but when I use g.DrawRectangle() it is drawing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.