# [solved] Object instead of a pixel

This topic is 4349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi I already searched for my problem in the forum but without success. So here is my question/problem: Basically I want to draw an 3d-object instead of a pixel of the base object. For example I draw a triangle with the common vertex-code. That's no problem, but here comes the challange: For every single pixel containing this triangle I want to draw a new, smaller coordinate system. Example: The pixels of the triangle are visualised with a sphere in the according coordinate system, then the triangle consists of many spheres. Does anybody know how to realise this? Is there any example/tutorial/link which explains it to me? reani [Edited by - reani on September 22, 2006 7:33:36 AM]

##### Share on other sites
I didn't understand what you want to do, but can try the following:

Read the pixel buffer after rendering the triangle, check each pixel for the triangle's color, project the pixel's position + depth value into the world again and draw a sphere there.

Question:

Why would you want to draw a sphere instead of a pixel? When using the same projection matrix, the sphere would end in beeing drawn as a pixel again, so where's the difference?

##### Share on other sites
Every pixel of the triangle belongs to additional infomation. I use the sphere to visualise this infomation.
My fault: not every pixel is visualised with a sphere.

For a better understanding i found a picture in the web:
http://www.informatik.uni-leipzig.de/bsv/Hlawit/Glyphs/glyphs/glyphs-000002.png

This picture shows what i want to implement.

##### Share on other sites
Seems to be a huge n x m matrix.
Why don't you create a 2D array containing the information, store position and orientation of the "sphere" and render the spheres by traversing the array?

If that background is a texture: just deal with the texture as an array. Load it into OpenGL for rendering but keep a copy for reading.

If that texure should be dynamic, use render to texture or read back the pixels using glReadPixels (you don't have to read every pixel, just the ones you want to use).

##### Share on other sites
No, you cannot tell openGl to replace all pixels in a surface with 3d objects automatically.

If you want to draw a grid of these spheres... you're going to have to do it yourself. This is easily accomplished using a 2d array...

I suspect, that you are trying for something more difficult, rather than a flat plane of these spheres, you are probably trying to cover an arbitrary surface with them.
You're just going to have to go through your triangle, and use linear interpolation between it's vertices to calculate postions for each of theres spheres 'manually'.

##### Share on other sites
ok, i think i understand what i have to do, but i'm confused :-(

I'm not that familiar with OpenGL. Do you have an example or a tutorial for me?

##### Share on other sites
I don't have a tutorial right now, but you can do the following:

If the surface you want to cover is static, you can build a list of positions to cover in a preprocess, then loop through this list and draw an object at each of those positions.

If the surface will be deformable, you'd have to loop through its vertices each frame or build the list I mentioned above and only update the deformed parts.

Now for the interpolation. It's basically just some vector math:

Get two neighboring vertices, calculate the vector between them (v2 - v1) + its length. Get the number of interpolated points = length / prefered distance (the distance your objects should have). Each interpolated point will be calculated as: v1 + Normalize(v2 - v1) * distance.

This way you can cover the edges of your primitives with objects.

When using rectangluar Quads you could also use the interpolated points on the edge to calculate the interior points. For non-rectangluar primitives you would have to figure it out on your own.

At the end, draw an object at each position you calculated. You could use glut for drawing spheres or create your own objects.

##### Share on other sites
hi again,

ok, i found a way for doing my first example, but i doesn't work. Idea is that i draw a triangle and on every corner i add - at the beginning - a line. The line will be replaced by a sphere later, that's why i draw the line in a list (see below).

Here's my routine:
glBegin(GL_TRIANGLES);	glVertex3dv(&vdata[tindices[0]][0]);	glCallList(1);	glVertex3dv(&vdata[tindices[1]][0]);	glCallList(1);	glVertex3dv(&vdata[tindices[2]][0]);	glCallList(1);glEnd();

and my list declaration:

glNewList(1, GL_COMPILE);	glBegin(GL_LINES);		glPushMatrix();		glVertex3d( 1.0, 1.0,-1.0);		glVertex3d( 1.0, 1.0, 1.0);		glPopMatrix();	glEnd();		glEndList();

The scene only shows a mix of triangle and line. I tried the triangle without the lines and vice versa: works!

Does anybody know what's wrong?

reani

##### Share on other sites
Put the glPushMatrix() and glPopMatrix() outside your list definition.

You don't draw the triangle, right?

so do the following:

Render(){  glPushMatrix();  glTranslatef(corner.x, corner.y, corner.z);  //convert your &vdata[tindices[0]][0] to those 3 floats  glCallList(1);  glPopMatrix();  //repeat for the 2 remaining corners.};

if you want to render the triangle, too, put that glBegin(GL_TRIANGLES) + glVertex3f(...) etc. stuff at the beginning or end of the Render() function but without the glCallList(1)s.

##### Share on other sites
i render the triangle too, but anyway thank for solving the problem!

Except there was something missing: after the
glCallList(1);

you have to insert:
glTranslatef(-corner.x, -corner.y, -corner.z);

... the transformation back to the coordinates.

reani

1. 1
2. 2
3. 3
4. 4
frob
13
5. 5

• 16
• 13
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632170
• Total Posts
3004550

×