Missing pixels in openGL

I dont know if anyone was mentioned this, but is it possible to draw a complete non-filled rectangle in ofRect? Currently the top right pixel is always missing

GL_QUADS creates a filled rectangle without this problem but GL_LINE_LOOP has a small gap.

Currently I have a rect function that draws a filled rect of white and then a slightly smaller rect of the background colour, but its not ideal :slight_smile:

ofFill();
ofSetColor(0xFFFFFF);
ofRect(left, top, width, width);
ofSetColor(0x000000);
ofRect(left+1, top+1, width-2, height-2);

can you post a screen shot of what you mean?

it might be the same problem as this:
http://forum.openframeworks.cc/t/gllinewidth-amp;-broken-lines/231/0

it’s sounds like a common opengl thing, that it doesn’t do line joins very well.

http://www.opengl.org/resources/faq/tec-…-zation.htm

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

does the same problem happen if you enable smoothing?

take care - zach

Here is my hacked ofRect to make this work, and still work with OF_RECTMODE_CENTER and filled rects. Can you see anything wrong doing it this way?

I’ve tested with the 4 variations of function call and it works fine.

  
  
void ofRect(float x,float y,float w,float h){  
  
	// use smoothness, if requested:  
	if (bSmoothHinted && drawMode == OF_OUTLINE) startSmoothing();  
  
	// offset for rect mode  
	int offsetx = 0;  
	int offsety = 0;  
	if (cornerMode == OF_RECTMODE_CENTER){  
		offsetx = -(w/2);  
		offsety = -(h/2);  
	}  
  
	// draw filled rect  
	if(drawMode == OF_FILLED){  
		glBegin( GL_QUADS );     
		glVertex2f(x+offsetx,y+offsety);  
		glVertex2f(x+w+offsetx,y+offsety);  
		glVertex2f(x+w+offsetx,y+h+offsety);  
		glVertex2f(x+offsetx,y+h+offsety);  
		glEnd();  
	}else{ // drop open rect  
		glBegin(GL_LINES);  
		// top line  
		glVertex2f(x+offsetx,y+offsety);  
		glVertex2f(x+w+offsetx+1,y+offsety); // notice the +1 on x  
		// bottom line  
		glVertex2f(x+offsetx,y+h+offsety);  
		glVertex2f(x+w+offsetx,y+h+offsety);  
		glEnd();  
  
		glBegin(GL_LINES);  
		// left vertical line  
		glVertex2f(x+offsetx,y+offsety);  
		glVertex2f(x+offsetx,y+h+offsety);  
		// right vertical line  
		glVertex2f(x+w+offsetx,y+offsety);  
		glVertex2f(x+w+offsetx,y+h+offsety);  
		glEnd();  
	}  
  
	// use smoothness, if requested:  
	if (bSmoothHinted && drawMode == OF_OUTLINE) endSmoothing();  
}  
  

wow, I never saw that before, but it is definitely an opengl bug and it might be highly related to the graphics card. I wonder about macs, intel graphics etc. I am on an nvidia.

I have the same problem, and you solution fixes the problem, but I don’t think the solution will work when you rotate the rectangle

ofSetRectMode(OF_RECTMODE_CENTER);
glTranslatef(200,200,0);
glRotatef(ofGetElapsedTimeMillis()/10000.0f, 0,0,1);
ofRect(0,0,200,200);

at some points, I see that extra pixel, which is more obvious then the missing pixel…

another solution might be to draw 1-pixel rectangles at all the vertices -

I’ll experiment on another graphics card and see how that goes.

take care!
zach

Oh yeah, I forgot about rotation of the rect :slight_smile:

My video card is an nvidia geforce go 7400.

Just doing some tests…In Flash, if I draw a vector rect (by hand, not code), at runtime at 100% zoom I have the same missing pixel, but this time in the lower right corner. Processing doesn’t seem to have a missing pixel.

weird stuff -

I am also on a 7400, so I wonder how much of this is just us.

does processing in opengl mode have a missing pixel?

thanks!
zach

I thought it did, but I tried it and it didn’t.

This might help
http://dev.processing.org/bugs/show-bug.cgi?id=97

“there are just problems when points are duplicated. like when the last
point in the shape meets the first, which happens with curves and i need to
re-add detection code to avoid it.”