PDA

View Full Version : help a fellow coder in need



mattc
10-28-2002, 08:43 PM
hi. can you help with these questions?

1) proper bump/reflection/refraction mapping: could you please point me to some sample code (don't need an entire app) that only uses opengl 1.3 and/or arb extensions? i've got nvidia sdk but it relies on nv_combiners etc, i'm looking for a method that (a) is not reliant on a specific card/manufacturer, (b) allows me to vary the intensity of bumping *and* highlight colour/strength (preferrably dynamically and per vertex, but per triangle's okay too)

2) somewhat related to the above, i understand that, for max performance, you need to use vertex programs (otherwise it's respecify entire world geometry every frame): opengl 1.4 pdf doesn't say how you write vertex programs, is there a place where i can get language spec/syntax reference, like intel assemebly opcodes? hopefully some simple example code chunks, as i want to explore custom lighting etc.

3) colour/convolution matrix (the imaging subset): again, glspec 1.4 pdf is too abstract for my coding brain - are there any decent code samples on potential application? specifically, i wanna know if you can use it for things like hue rotation, on-the-fly tinting/grayscaling/colour space inversion (like a smooth "flash" from negative to normal image colours).

i haven't been able to play with these features cos there's no opengl 1.3/1.4 sdk for win32 and i'm in the process of building my own headers/libs, and all of these features are post-1.1 version of opengl. formal gl spec is quite impenetrable in places and i prefer to learn through code, so if you could help/point me to a good resource, i'd be well grateful http://www.opengl.org/discussion_boards/ubb/smile.gif if it helps in any way, i've done around 10 years of c/c++ and about 3-4 years of opengl 1.1. thanks for reading http://www.opengl.org/discussion_boards/ubb/smile.gif

JONSKI
10-29-2002, 07:42 PM
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/007714.html
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/007732.html


Here's some snippets from a program I made:



typedef void (__stdcall *PFNGLGENPROGRAMSARB) ( int n, const unsigned int
*programs );
typedef void (__stdcall *PFNGLBINDPROGRAMARB) ( const int target, unsigned
int program );
typedef void (__stdcall *PFNGLPROGRAMSTRINGARB) ( const int target, const
int format, int len, const void *string );


PFNGLGENPROGRAMSARB glGenProgramsARB = NULL;
PFNGLBINDPROGRAMARB glBindProgramARB = NULL;
PFNGLPROGRAMSTRINGARB glProgramStringARB = NULL;


// membrane effect (as seen in nVidia effects browser)
const unsigned char myprogram[] = "!!ARBvp1.0 \n\
# variable declarations\n\
TEMP xfNorm, xfPos, r0;\n\
# transform vertex to clip cooridinates\n\
DP4 result.position.x, state.matrix.mvp.row[0], vertex.position;\n\
DP4 result.position.y, state.matrix.mvp.row[1], vertex.position;\n\
DP4 result.position.z, state.matrix.mvp.row[2], vertex.position;\n\
DP4 result.position.w, state.matrix.mvp.row[3], vertex.position;\n\
# produce point-to-eye vector\n\
DP4 xfPos.x, state.matrix.modelview.row[0], vertex.position;\n\
DP4 xfPos.y, state.matrix.modelview.row[1], vertex.position;\n\
DP4 xfPos.z, state.matrix.modelview.row[2], vertex.position;\n\
DP4 xfPos.w, state.matrix.modelview.row[3], vertex.position;\n\
# normalize point-to-eye vector\n\
DP3 r0.x, xfPos, xfPos;\n\
RSQ r0.x, r0.x;\n\
MUL xfPos, xfPos,-r0.x;\n\
# transform normal to eye coordinates\n\
DP3 xfNorm.x, state.matrix.modelview.invtrans.row[0], vertex.normal;\n\
DP3 xfNorm.y, state.matrix.modelview.invtrans.row[1], vertex.normal;\n\
DP3 xfNorm.z, state.matrix.modelview.invtrans.row[2], vertex.normal;\n\
# determine color\n\
DP3 r0.x, xfPos, xfNorm;\n\
ADD result.color, vertex.normal.w,-r0.x;\n\
MOV result.texcoord[0].x, r0.x;\n\
END";


// cloaked object effect
const unsigned char myprogram[] = "!!ARBvp1.0 \n\
# variable declarations\n\
TEMP xfNorm, xfPos, xfLit, Half, r0;\n\
# transform vertex to clip cooridinates\n\
DP4 result.position.x, state.matrix.mvp.row[0], vertex.position;\n\
DP4 result.position.y, state.matrix.mvp.row[1], vertex.position;\n\
DP4 result.position.z, state.matrix.mvp.row[2], vertex.position;\n\
DP4 result.position.w, state.matrix.mvp.row[3], vertex.position;\n\
# produce point-to-eye vector\n\
DP4 xfPos.x, state.matrix.modelview.row[0], vertex.position;\n\
DP4 xfPos.y, state.matrix.modelview.row[1], vertex.position;\n\
DP4 xfPos.z, state.matrix.modelview.row[2], vertex.position;\n\
DP4 xfPos.w, state.matrix.modelview.row[3], vertex.position;\n\
# normalize point-to-eye vector\n\
DP3 r0.x, xfPos, xfPos;\n\
RSQ r0.x, r0.x;\n\
MUL xfPos, xfPos,-r0.x;\n\
# transform normal to eye coordinates\n\
DP3 xfNorm.x, state.matrix.modelview.invtrans.row[0], vertex.normal;\n\
DP3 xfNorm.y, state.matrix.modelview.invtrans.row[1], vertex.normal;\n\
DP3 xfNorm.z, state.matrix.modelview.invtrans.row[2], vertex.normal;\n\
# produce light vector\n\
ADD xfLit, state.light[0].position,-xfPos;\n\
# normalize light vector\n\
DP3 r0.x, xfLit, xfLit;\n\
RSQ r0.x, r0.x;\n\
MUL xfLit, xfLit, r0.x;\n\
# compute half vector\n\
ADD Half, xfLit, xfPos;\n\
# normalize half vector\n\
DP3 r0.x, Half, Half;\n\
RSQ r0.x, r0.x;\n\
MUL Half, Half, r0.x;\n\
# determine color\n\
DP3 r0.y, xfNorm, Half;\n\
MOV r0.w, state.material.shininess;\n\
LIT r0, r0;\n\
DP3 r0.x, xfNorm, xfPos;\n\
MUL r0.z, r0.z, r0.z;\n\
ADD result.color, r0.z,-r0.x;\n\
END";


glGenProgramsARB = (PFNGLGENPROGRAMSARB)wglGetProcAddress(
"glGenProgramsARB" );
glBindProgramARB = (PFNGLBINDPROGRAMARB)wglGetProcAddress(
"glBindProgramARB" );
glProgramStringARB = (PFNGLPROGRAMSTRINGARB)wglGetProcAddress(
"glProgramStringARB" );
if (!glGenProgramsARB | | !glBindProgramARB | | !glProgramStringARB) {
MessageBox( NULL, "Unable to retrieve vertex program procedure
addresses.", "", MB_OK );
return false; }
glGenProgramsARB( 1, programs );
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, programs[0] );
glProgramStringARB( GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen( (const char*)myprogram ), myprogram );
if (glGetError() == GL_INVALID_OPERATION) // tripped
MessageBox( NULL, "Invalid Operation", "", MB_OK );


// ... and last, but not least, our beloved glEnable() call.
glEnable( GL_VERTEX_PROGRAM_ARB );

mattc
10-30-2002, 05:54 PM
thanks, code chunks are always handy, but i was primarily looking for the vertex program _language_ reference... gl 1.4 pdf has nothing to say on that, there must be a proper language spec somewhere http://www.opengl.org/discussion_boards/ubb/smile.gif

any takers on the other two?

pbrown
10-30-2002, 06:13 PM
The ARB_vertex_program extension spec can be found at:
http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_program.txt


[This message has been edited by pbrown (edited 10-31-2002).]

mattc
10-30-2002, 09:33 PM
phew. that'll keep me busy for years http://www.opengl.org/discussion_boards/ubb/wink.gif thanks

what about the imaging subset? as far as i can remember right now, even my lowly gf2 supports it... sort of makes sense, cos as far as i know, according to gl spec the subset is either supported or not, and since the very common additive blending is part of it, you get the whole subset functionality?