PDA

View Full Version : Distort an image in a grid with a bump map



sammy
06-12-2008, 08:03 AM
Hello OpenGL programmers,

Please help this inexperienced programmer! I guess it shouldn't be too difficult, especially if you know some OpenGL.

I try to figure out a way to generate a grid of vertices in 3D space. I managed to get the grid, but the texture I wanted to attach to it, doesn't show at all on the screen.

First question: how do I attach the texture to the grid?

The next step is to take values from a gray level map or bump map. Then for every vertex point, take the gray value (from 0 to 255) and multiply the z-coordinate of the vertex with it. This way, you actually get heights in the image.

So the second question is: How do I get the gray level of a map for each vertex point and make it result in a difference in height?

The idea is that the parts that were light in the gray level map, appear as magnified parts of an image on the screen because they are placed higher in the grid.

I actually work with Processing, but this also uses OpenGL. I also started a discussion here: http://processing.org/discourse/yabb_bet...58341;start=0#7 (http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1212958 341;start=0#7)

Some code:

int w = 1280;
int h = 800;
int nx = 81; // number of vertices x + 1
int ny = 51; // number of vertices y + 1
int nz = 255;
int ls = 16; // length squares of grid; 1280/80 and 800/50
int verX;
int verY;
int[] vertexX = new int[nx];
int[] vertexY = new int[ny];
int[] vertexZ = new int[nz];
PImage img;

void setup() {
size(w, h, P3D);
img = loadImage("VincentsRoom2L.jpg");
image(img, 0, 0);
for (int i = 0; i < nx; i++) {
vertexX[i] = i * ls;
verX = i * ls;
for (int j = 0; j < ny; j++) {
vertexY[j] = j * ls;
verY = j * ls;
ellipse(verX, verY, 5, 5);
}
}
}

void draw() {
background(255);
textureMode(NORMALIZED);
rotateY(map(mouseX, 0, width, 0, PI*0.738));
beginShape(POINTS);
texture(img);
for (int i = 0; i < nx; i++) {
int x = vertexX[i];
for (int j = 0; j < ny; j++) {
int y = vertexY[j];
vertex(x, y, 0);
vertex(x, y, 0);
}
}
endShape();
}


I think the answer must be somewhere here: http://processing.org/learning/3d/texturedsphere.html as these guys textured a whole sphere!

For me it's so difficult I've spent some days pondering about this. But maybe you have the solution? It would really help me as it is for a project with a deadline...

Or maybe you have a smarter idea to magnify areas of an image? If you know how I should solve this, please help me and I'll give you credit in my project.