Strange 2D problem

“Hello World\n”,
i used the following code to draw 2 rectangles on the screen:

SDL_SetVideoMode(1024, 768, 32, SDL_OPENGL);

glViewport(0, 0, 1024, 786);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 1024, 0, 786);
glColor3f(1, 1, 1);

glBegin(GL_LINES);
glVertex2i(100, 100);
glVertex2i(200, 100);

glVertex2i(200, 100);
glVertex2i(200, 200);

glVertex2i(200, 200);
glVertex2i(100, 200);

glVertex2i(100, 200);
glVertex2i(100, 100);
glEnd();

glBegin(GL_LINE_STRIP);
glVertex2i(350, 350);
glVertex2i(400, 350);
glVertex2i(400, 400);
glVertex2i(350, 400);
glVertex2i(350, 350);
glEnd();

The result and the problem you can see at
http://www.isource.de/strange/strange.png
http://www.isource.de/strange/strange_zoomed.png

on other computers in fullscreen mode sometimes the left border isn’t
drawn?!?

What’s wrong?

Tnx,
Florian

glBegin(GL_LINES);
glVertex2i(100, 100);
glVertex2i(200, 100);

glVertex2i(200, 100);
glVertex2i(200, 200);

glVertex2i(200, 200);
glVertex2i(100, 200);

glVertex2i(100, 200);
glVertex2i(100, 100);
glEnd();

I think it should work if you draw a polygon (eg: GL_QUADS) with
glPolygonMode set to GL_LINE. I believe the reason for the missing
pixel using the GL_LINES as you have is so that connected lines
wouldn’t overlap. For example, if you draw a line from 0-100 and
another line from 100-200, you wouldn’t want two pixels to be drawn at
100 (consider if the lines were transparent, the middle pixel would
look different).

At least, this is what I’m led to speculate based on Chapter 2 of the
red book under the “Polygon Details” section:

http://rush3d.com/reference/opengl-redbook-1.1/chapter02.html

I assume this behavior would translate to lines as well - maybe
someone who knows for sure will let us know :slight_smile:

-Mike

Quoth Florian Liefers , on 2005-04-20 00:40:18 +0000:

glBegin(GL_LINES);
[…]
glEnd();

glBegin(GL_LINE_STRIP);
[…]
glEnd();

While this doesn’t directly answer your question, the theoretically
correct way to draw series of lines known to be looping in OpenGL is
with GL_LINE_LOOP.

glBegin(GL_LINE_LOOP);
glVertex2i(100, 100);
glVertex2i(100, 200);
glVertex2i(200, 200);
glVertex2i(200, 100);
/* don’t specify the first coordinate again */
glEnd();

—> Drake Wilson
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050419/ed8fb2a1/attachment.pgp

[…]

A line is a 1 dimensional object which you’d like to draw on a 2D screen.
If you specify your point/line coordinates exactly at integer positions, it is
highly driver dependend where your pixel is drawn (I’ve tried nvidia, ati and
mesa drivers with different results).

The red book suggests to translate x and y by 0.375.
See also
http://rush3d.com/reference/opengl-redbook-1.1/appendixh.html

This works in most cases.

Johannes Schmidt

< http://libufo.sourceforge.net > The OpenGL GUI ToolkitAm Mittwoch 20 April 2005 02:40 schrieb Florian Liefers:

“Hello World\n”,
i used the following code to draw 2 rectangles on the screen:

SDL_SetVideoMode(1024, 768, 32, SDL_OPENGL);

glViewport(0, 0, 1024, 786);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 1024, 0, 786);
glColor3f(1, 1, 1);

I think it should work if you draw a polygon (eg: GL_QUADS) with
glPolygonMode set to GL_LINE. I believe the reason for the missing
pixel using the GL_LINES as you have is so that connected lines
wouldn’t overlap. For example, if you draw a line from 0-100 and
another line from 100-200, you wouldn’t want two pixels to be drawn at
100 (consider if the lines were transparent, the middle pixel would
look different).

But when i do it with GL_LINE_STRIP, which connect the lines by itself,
i get the same result with the missing pixel. But i will try your tip :-).
If this works i have another problem when i draw my selection box
which looks like


| |

| |


Hope you can imagine how it should look like :-). When i draw this i got it
this way:

– - <-- missing pixel
| |

| |


Tnx for your reply,
Florian

[…]

A line is a 1 dimensional object which you’d like to draw on a 2D screen.
If you specify your point/line coordinates exactly at integer positions, it is
highly driver dependend where your pixel is drawn (I’ve tried nvidia, ati and
mesa drivers with different results).

The red book suggests to translate x and y by 0.375.

I tried it this way but the result is exactly the same.
I have problems to understand how this can happen when using GL_LINE_STRIP.
The crack is at an edge in the middle of the strip and should be connected
automaticaly.

Tnx for your reply,
Florian

This is possibly a bug in your OpenGL implementation.

Please send a complete minimal example. I can’t reproduce this error (using
Mesa 6.2.1).
Which platform and which graphics driver do you use?

Johannes Schmidt

< http://libufo.sourceforge.net > The OpenGL GUI ToolkitAm Mittwoch 20 April 2005 11:58 schrieb Florian Liefers:

A line is a 1 dimensional object which you’d like to draw on a 2D screen.
If you specify your point/line coordinates exactly at integer positions,
it is highly driver dependend where your pixel is drawn (I’ve tried
nvidia, ati and mesa drivers with different results).

The red book suggests to translate x and y by 0.375.

I tried it this way but the result is exactly the same.
I have problems to understand how this can happen when using GL_LINE_STRIP.
The crack is at an edge in the middle of the strip and should be connected
automaticaly.

[…]

This is possibly a bug in your OpenGL implementation.

Please send a complete minimal example. I can’t reproduce this error (using
Mesa 6.2.1).
Which platform and which graphics driver do you use?

Platform: WinXP
Compiler: MinGW/GCC
Development-Environment: Eclipse/CDT
Graphics: Ati Mobility Radeon 9600 Pro, Driverversion: 6.14.10.6392
(30.10.2003)
(Problem also exists on other Notebooks/Displays)
SDL-Version: 1.2.5
Libraries linked: SDL, SDL_image, SDL_net, glut32, glu32, opengl32

=== code ===
#include “…/contrib/SDL/include/SDL.h”
#include “…/contrib/SDL/include/SDL_net.h”
#include “…/contrib/SDL/include/SDL_opengl.h”
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#ifdef _WIN32
#undef main
#endif

int main(int argc, char *argv[]) {
if (SDL_Init(SDL_INIT_VIDEO)<0) {
fprintf( stderr, “Video initialization failed: %s\n”, SDL_GetError());
SDL_Quit();
}
atexit(SDL_Quit);
SDL_SetVideoMode(1024, 768, 32, SDL_OPENGL);
while (true) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, 1024, 786);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 1024, 0, 786);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.375f, 0.375f, 0.0f);
glColor3f(1, 1, 1);
glBegin(GL_LINES);
glVertex2i(100, 100);
glVertex2i(200, 100);
glVertex2i(200, 100);
glVertex2i(200, 200);
glVertex2i(200, 200);
glVertex2i(100, 200);
glVertex2i(100, 200);
glVertex2i(100, 100);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2i(350, 350);
glVertex2i(400, 350);
glVertex2i(400, 400);
glVertex2i(350, 400);
glVertex2i(350, 350);
glVertex2i(400, 350);
glEnd();
glPolygonMode(GL_FRONT, GL_LINE);
glBegin(GL_QUADS);
glVertex2i(100, 300);
glVertex2i(150, 300);
glVertex2i(150, 350);
glVertex2i(100, 350);
glEnd();
glPolygonMode(GL_FRONT, GL_FILL);
SDL_GL_SwapBuffers();
SDL_Event event;
SDL_PollEvent(&event);
SDL_Delay(200);
}
SDL_Quit();
return 0;
}
=== /code ===

Florian Liefers

Using SDL 1.2.8, Mesa 6.2.1, XFree86 4.3,
it looks as expected:
http://libufo.sf.net/gl2d_lines.png

Perhaps you should update your graphics card driver?

Regards,
Johannes Schmidt

< http://libufo.sourceforge.net > The OpenGL GUI ToolkitAm Mittwoch 20 April 2005 14:32 schrieb Florian Liefers:

This is possibly a bug in your OpenGL implementation.

Please send a complete minimal example. I can’t reproduce this error
(using Mesa 6.2.1).
Which platform and which graphics driver do you use?

Platform: WinXP
Compiler: MinGW/GCC
Development-Environment: Eclipse/CDT
Graphics: Ati Mobility Radeon 9600 Pro, Driverversion: 6.14.10.6392
(30.10.2003)
(Problem also exists on other Notebooks/Displays)
SDL-Version: 1.2.5
Libraries linked: SDL, SDL_image, SDL_net, glut32, glu32, opengl32

I’ve tried the code and it worked for me. No missing pixels.

It’s a glitch in your graphics driver.

c.-
http://www.cesaremarilungo.com

Florian Liefers wrote:

[…]

This is possibly a bug in your OpenGL implementation.

Please send a complete minimal example. I can’t reproduce this error
(using Mesa 6.2.1).
Which platform and which graphics driver do you use?

Platform: WinXP
Compiler: MinGW/GCC
Development-Environment: Eclipse/CDT
Graphics: Ati Mobility Radeon 9600 Pro, Driverversion: 6.14.10.6392
(30.10.2003)
(Problem also exists on other Notebooks/Displays)
SDL-Version: 1.2.5
Libraries linked: SDL, SDL_image, SDL_net, glut32, glu32, opengl32

=== code ===
#include “…/contrib/SDL/include/SDL.h”
#include “…/contrib/SDL/include/SDL_net.h”
#include “…/contrib/SDL/include/SDL_opengl.h”
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#ifdef _WIN32
#undef main
#endif

int main(int argc, char *argv[]) {
if (SDL_Init(SDL_INIT_VIDEO)<0) {
fprintf( stderr, “Video initialization failed: %s\n”,
SDL_GetError());
SDL_Quit();
}
atexit(SDL_Quit);
SDL_SetVideoMode(1024, 768, 32, SDL_OPENGL);
while (true) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, 1024, 786);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 1024, 0, 786); glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.375f, 0.375f, 0.0f);
glColor3f(1, 1, 1);
glBegin(GL_LINES);
glVertex2i(100, 100);
glVertex2i(200, 100);
glVertex2i(200, 100);
glVertex2i(200, 200);
glVertex2i(200, 200);
glVertex2i(100, 200);
glVertex2i(100, 200);
glVertex2i(100, 100);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2i(350, 350);
glVertex2i(400, 350);
glVertex2i(400, 400);
glVertex2i(350, 400);
glVertex2i(350, 350);
glVertex2i(400, 350);
glEnd();
glPolygonMode(GL_FRONT, GL_LINE);
glBegin(GL_QUADS);
glVertex2i(100, 300);
glVertex2i(150, 300);
glVertex2i(150, 350);
glVertex2i(100, 350);
glEnd();
glPolygonMode(GL_FRONT, GL_FILL);
SDL_GL_SwapBuffers();
SDL_Event event;
SDL_PollEvent(&event);
SDL_Delay(200);
} SDL_Quit();
return 0;
}
=== /code ===

Florian Liefers


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Johannes Schmidt schrieb:>Am Mittwoch 20 April 2005 14:32 schrieb Florian Liefers:

Using SDL 1.2.8, Mesa 6.2.1, XFree86 4.3,
it looks as expected:
http://libufo.sf.net/gl2d_lines.png

Perhaps you should update your graphics card driver?

I updated my graphics card driver, updated to SDL 1.2.8 and used other
opengl-libs to link, but
the result is exactly the same.
Maybe someone can compile this little sample to a w32 executable and
give me a link to download
or send it direct to @Florian_Liefers that i can see if my libraries are
responsible for
this problem. That would be very nice.
I googled for an opengl-application wich only shows amongst others a
lined rectancle, but with no success :-(.

Tnx,
Florian