PDA

View Full Version : OpenGL texture mapping



jacky_cheecheo
04-14-2003, 10:19 AM
Hi,

I'm currently trying to do texture mapping without the functions from openGL.

Let's say, i build a quad with opengl like this:

glBegin(GL_QUADS);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glEnd();

Is it possible that i do texture mapping on that quad without the use of glTexCoord(), glBindTexture(), and other functions?

Any advice is welcome.

knackered
04-14-2003, 10:29 AM
Yes, draw on your screen with the crayons the warden gave you.

jacky_cheecheo
04-14-2003, 11:14 AM
so i that take as a no for an answer!

Any other suggestions? Anyone?

jra101
04-14-2003, 11:26 AM
You could draw a ton of quads, each a pixel in size and set the quad's color to the corresponding pixel in your texture.

Coconut
04-14-2003, 12:02 PM
Can you tell us why you are asking this?

Humus
04-14-2003, 01:42 PM
You can get rid of glTexCoord2f() calls by using glTexGen().

raverbach
04-15-2003, 06:16 AM
Originally posted by jra101:
You could draw a ton of quads, each a pixel in size and set the quad's color to the corresponding pixel in your texture.

http://www.opengl.org/discussion_boards/ubb/biggrin.gif
this is also very very fast

jacky_cheecheo
04-15-2003, 06:30 AM
Hi raverbach,

I think you solution could be the answer to my question. But i have a small request, how exactly should i get the color value from the texture and how to convert it to RGB and put the corresponding values into glColor3f()?

Thank you very much!

cass
04-15-2003, 06:57 AM
??

Jacky,

Why can't you just use the texture mapping API?

You could do your own software rasterization and shading and draw everything with glDrawPixels(), but at some point we cross over into absurdity.

You need to explain why you can't use the texture mapping API first.

Thanks -
Cass

jacky_cheecheo
04-15-2003, 07:04 AM
To tell you the truth, it's part of a project that i'm doing. The objective is to achieve texture mapping without using openGL's texture mapping functions.

I hope this clears your doubt on me. So, is this acceptable?

Coconut
04-15-2003, 07:30 AM
Not really. Is it your school assignment question which came up by your professor?
Or it is a course project which you came up this goal?

jacky_cheecheo
04-15-2003, 07:52 AM
To further clarify your doubt on me, yes this is a course project that i came up with to achieve this goal...

Can you pls. tell me whether this is possible?

Proton
04-15-2003, 08:03 AM
Thats a strange goal. But I think it could be accomplished with fragment shaders. Just send in the texture without uv data, then create some uv data within the shader.

Complicated solution to a simple problem. I still like the crayon idea http://www.opengl.org/discussion_boards/ubb/wink.gif

jacky_cheecheo
04-15-2003, 08:10 AM
First of all, i would like to thank all the contributors for spending their precious time looking into this problem for me...Actually i already tried to build tons of polygon. This idea came from some of the contributors and i would like to take this opportunity to thank them again.

Although i've manage to build 1000 x 1000 for a quad, but i still can't manage to figure out how to get the texels colour and apply it into glColor3f(). Can anyone show me how?

I can send those who are interested and willing to help me, the application + source codes.

Regards,
Jacky

JustHanging
04-15-2003, 08:14 AM
Might as well forget about opengl and write your own rasterizer. That way it'd make some sense, but trying to do texturing in opengl without the opengl texturing functions... Why don't you draw triangle meshes without using triangles while you're at it http://www.opengl.org/discussion_boards/ubb/smile.gif

-Ilkka

jacky_cheecheo
04-15-2003, 08:41 AM
I say sorry if programmers out there think that my objective in this project is foolish, but i have no turning back except find a solution to my problem!

I hope some of the programmers can give me an answer.

Thank you in advance!

pkaler
04-15-2003, 09:43 AM
Whip out your copy of Foley, and VanDam and start writing your own software renderer.

That's what you seem to be wanting to do.

cass
04-15-2003, 10:23 AM
Jacky,

I apologize if I sounded unduly harsh. It's more interesting to work on a problem if it's not just "make work", so if you had a real need for this kind of functionality and you couldn't use the texture mapping API, then it might have been semi-interesting.

Ultimately, though, texture mapping - while straightforward - is fairly expensive. You can display images that use texture mapping in OpenGL without using OpenGL texture mapping, but to do so you have to implement texture mapping in software, and that makes OpenGL (and any hardware support it provides) pretty much irrelevant.

So your options are:

- software renderer w/ glDrawPixels at the end
- polygon dicing w/ per-vertex glColor


I'll leave it to you to figure out how to implement these options.

Thanks -
Cass

JustHanging
04-15-2003, 10:29 PM
I'm sorry too, if I sounded harsh. But you are trying to find a solution to a solved problem and your solution is obviously going to be slower and more difficult than the existing one.

Maybe you could implement displacement mapping instead? You could subdivide the polys and do the lookups just like you would with texturing, but then you'd displace the surfaces instead of just painting them. That way you'll get an effect that's remotely worth the effort.

With that I'll be glad to help you.

-Ilkka

rgpc
04-15-2003, 10:35 PM
Are you only trying to draw a single quad?

Or are you trying to draw more complex geometry with texture mapping and not using the gl Functions?

If it's the latter I'd say "Good luck" or "Use D3D (booo!)".

If it's the former then just create a number of quads (x by y quads) where x by y is the dimension of your image and build the color values for your vertices according to the corresponding pixel color in your image. Each quad will be x -> x+ 1 and y -> y+ 1 with z = 0.

It's quite easy in reality but it's going to be flipping slow (256 x 256 will equal 65536 quads and 262144 vertices!)

Of course you could just do something sensible and use the gl functions. Or, if you don't want to use glTexCoord() you could use TexPointer() and DrawElements...

jacky_cheecheo
04-16-2003, 12:24 AM
To be honest, there's no need for apologizing here bcos no offence is taken.

Back to the topic, can anyone further explain JustHanging's idea?

As for rgpc, actually speed is not a big matter here! The objective is to achieve texture mapping without opengl's functions (saying this makes me feel stupid!)

Actually i would like to try the idea that jra101 and raverbach suggested. Now i generated a 1000x1000 3D cube. the problem i'm facing now is that i can't seem to figure out how to get the RGB value from the bitmap.

PS: Can anyone show me how?

Thank you...

cbwan
04-16-2003, 12:36 AM
is this is what you want ?
http://www.flipcode.com/cgi-bin/msg.cgi?showThread=10-31-2002&forum=iotd&id=-1

"My goal was to write a simple converter that takes as input a textured triangle mesh, and outputs a colored voxel representation. No particular reason or overly fancy results, just experimenting a bit.

The approach I used to generate the voxel mesh is pretty simple. In a nutshell, it works like this:

# Generate a grid of cubes over the source mesh.
# Throw out any empty cubes.
# Color each of the remaining cubes based on the source mesh's texture. "

(Kurt Miller)

seb
[edit] I'm not kurt miller http://www.opengl.org/discussion_boards/ubb/wink.gif

[This message has been edited by cbwan (edited 04-16-2003).]

Ysaneya
04-16-2003, 12:38 AM
That's also a strange question: you've got your texture manually loaded into memory into a RGB[A] buffer, like this:



struct MyColor
{
unsigned char r, g, b, a;
};
MyColor *myTexture;
...
myTexture = new MyColor[256 * 256];


Then for a vertex, you'd find the UV coordinates, in the [0-255]*[0-255] range, and sample the texture with a glColor4ubv call:



glColor4ubv((unsigned char *)(myTexture + v * 256 + u)


Hope that helps.

Y.


[This message has been edited by Ysaneya (edited 04-16-2003).]

sanjo
04-16-2003, 12:52 AM
may have a look at this site : http://www.d6.com/users/checker/misctech.htm

it explains texture mapping.

JustHanging
04-16-2003, 12:58 AM
Look at this page, you should get the idea of displacement mapping. http://cmpa.ca.scad.edu/faculty/kesson/C...splacement.html (http://cmpa.ca.scad.edu/faculty/kesson/Ca301/wip/best_fall2002/jesse_kretschmer/displacement/displacement.html)

Technically there's nothing really difficult about it, now that you have your subdivided quad and can hopefully read the texture value from memory, all you need to do is move each vertex in the direction of the quad's normal the amount specified in the map.

You still need the normals for lighting, but we'll get back to it if you deciede to try displacement at all.

-Ilkka

raverbach
04-16-2003, 03:19 AM
I really think that if you´re trying to do some texture mapping without the OGL functions you should write your own rasterizer as previous posts mentioned it.
You´ll have far more control on what you´re going to do , and your projct is going to be far more exciting ....
I.e :a all the render in ps2 is custom made for the 128-bit emotion engine processor in assembler.

So choose your architecture ,and start some assembly and C coding.
http://www.opengl.org/discussion_boards/ubb/smile.gif

but that´s just my opinion

[This message has been edited by raverbach (edited 04-16-2003).]

raverbach
04-16-2003, 03:49 AM
but if you really want to stick to that 1 billion structure for a texturized polygon http://www.opengl.org/discussion_boards/ubb/smile.gif
Do what Ysaneya says , it will work perfectly i guess http://www.opengl.org/discussion_boards/ubb/smile.gif
There´s also other solutions using gl_points but it is slower than the the
bigquad
texture offset-> glcolor
approach

so try this one first




[This message has been edited by raverbach (edited 04-16-2003).]

raverbach
04-16-2003, 03:50 AM
ohnn not only bigquad , should work for triangles too http://www.opengl.org/discussion_boards/ubb/smile.gif

jacky_cheecheo
04-16-2003, 04:31 PM
Dear all,

thank you very much, finally i manage to do what i wanted to do. I followed raverbach's idea and now i achieve what i wanted!

And for those who helped in posting up your ideas, i would like to thank you all too...

Lastly, Good Day Everyone!

Regards,
Jacky