PDA

View Full Version : Any simple vertex programs?



02-07-2002, 07:34 PM
Was wondering if there are any simple vertex programs out there, say, like a nehe tutorial num 1 http://www.opengl.org/discussion_boards/ubb/smile.gif.. just a vertex proggy to say light a quad..

nexusone
02-08-2002, 05:36 AM
What is wrong with the nehe example?
Are you looking for a GLUT example of vertex array's?
I am not really shure what you are looking for?



Originally posted by Booga:
Was wondering if there are any simple vertex programs out there, say, like a nehe tutorial num 1 http://www.opengl.org/discussion_boards/ubb/smile.gif.. just a vertex proggy to say light a quad..

02-08-2002, 12:09 PM
There is nothing wrong with a nehe tut http://www.opengl.org/discussion_boards/ubb/smile.gif.. just wanted a tutorial like it that was easy and delt with vertex programs. (per pixel lighting, etc)

Thanks http://www.opengl.org/discussion_boards/ubb/smile.gif

nexusone
02-08-2002, 01:13 PM
Look at nehe 7 & 12 go into ligthing of objects.

You need to look at ploting vertex normals for surface lighting.

code will look something
like this.

glNornal3f( x, y,z );
glTexCoord2f(x,y);// if you are using a texture map.
glVertex3f( x, y, z);


Originally posted by Booga:
There is nothing wrong with a nehe tut http://www.opengl.org/discussion_boards/ubb/smile.gif.. just wanted a tutorial like it that was easy and delt with vertex programs. (per pixel lighting, etc)

Thanks http://www.opengl.org/discussion_boards/ubb/smile.gif

jmathies
02-08-2002, 02:25 PM
Originally posted by Booga:
Was wondering if there are any simple vertex programs out there, say, like a nehe tutorial num 1 http://www.opengl.org/discussion_boards/ubb/smile.gif.. just a vertex proggy to say light a quad..

OpenGL texture shader tutorial http://www.cfxweb.net/~projectfy/shaders.php

Diapolo
02-08-2002, 07:16 PM
I think he is talking about the GL_NV_vertex_program extension http://www.opengl.org/discussion_boards/ubb/smile.gif.
Thatīs the NV OGL thing for the DX8 vertex shaders.

I copied this from a NVIDIA demo, perhaps it helps:




#ifdef _WIN32
#include <windows.h>
#endif
#define GLH_NVEB_USING_NVPARSE
#define GLH_EXT_SINGLE_FILE
#include <glh_nveb.h>
#include <glh_extensions.h>
#include <glh_genext.h>
#include <glh_glut.h>
#include <glh_obs.h>
#include "array_texture.h"
#include "data_path.h"
#include "nv_png.h"
#include "nvparse.h"
#include "read_text_file.h"

// Declare the effect browser information

NVEB_EFFECT_NAME("Lit Quad");
NVEB_EFFECT_VERSION("1.0");
NVEB_EFFECT_LOCATION("Effects\\Basic");
NVEB_EFFECT_ABOUT(0, NULL, "Lit Quad", "NVEffectsExplained.htm#vtxprg_litquad");
NVEB_EFFECT_ABOUT(1, NULL, "NVIDIA Corporation", "http://www.nvidia.com");
NVEB_EFFECT_ABOUT(2, NULL, "Developer Relations", "http://www.nvidia.com/developer");
NVEB_EFFECT_EXTENSIONS("GL_NV_vertex_program");

using namespace glh;

glut_callbacks cb;
glut_simple_mouse_interactor camera, object;
glut_perspective_reshaper reshaper;

// Some structures for storing data.

struct xyzstruct {
float x;
float y;
float z;
};
struct uvstruct {
float u;
float v;
};

// Data for the Quad.
xyzstruct vertexdata[4];
xyzstruct normaldata[4];
uvstruct texuvdata[4];

// Vertex Program ID (Similar to a texture object ID)
// Vertex State Program ID (Similar to a texture object ID)
GLuint vpid;
GLuint vspid;

// Texture object for the texture.
tex_object_2D decaltex;


void CheckParseErrors()
{
for (char * const * errors = nvparse_get_errors(); *errors; errors++)
fprintf(stderr, *errors);
}

// Initialize data for the quad.
void InitializeQuadData()
{
vertexdata[0].x = -1; normaldata[0].x = 0; texuvdata[0].u = 0.0;
vertexdata[0].y = -1; normaldata[0].y = 0; texuvdata[0].v = 0.0;
vertexdata[0].z = 0; normaldata[0].z = 1;

vertexdata[1].x = 1; normaldata[1].x = 0; texuvdata[1].u = 1.0;
vertexdata[1].y = -1; normaldata[1].y = 0; texuvdata[1].v = 0.0;
vertexdata[1].z = 0; normaldata[1].z = 1;

vertexdata[2].x = 1; normaldata[2].x = 0; texuvdata[2].u = 1.0;
vertexdata[2].y = 1; normaldata[2].y = 0; texuvdata[2].v = 1.0;
vertexdata[2].z = 0; normaldata[2].z = 1;

vertexdata[3].x = -1; normaldata[3].x = 0; texuvdata[3].u = 0.0;
vertexdata[3].y = 1; normaldata[3].y = 0; texuvdata[3].v = 1.0;
vertexdata[3].z = 0; normaldata[3].z = 1;
}

// Display function.
void display()
{
glClear( GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT );

// Setup the viewing transformation
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
camera.apply_inverse_transform();
object.apply_transform();

// Vertex "state" programs are used to update data stored in constant
// memory. Vertex state programs differe from standard vertex programs
// in that they may read AND write to constant memory but may not write
// to the output registers.

// Run a vertex state program that transforms the light direction
// into object space and puts the result in c[4]. Also, transforms
// the view direction into object space and puts the result in c[8].
// Also, computes an object space H vector and stores in c[5].
// Normally you'd rotate the normal by the inverse transpose modelview,
// but rotating the light direction by the inverse modelview puts the
// light in object space - the same space as the normals.
float lightdir[4] = { 0.7071, 0.0, -0.7071, 0.0 };
// Put a camera space view vector in constant register 5
glProgramParameter4fNV( GL_VERTEX_PROGRAM_NV, 8, 0.0, 0.0, -1.0, 1.0 );
glExecuteProgramNV( GL_VERTEX_STATE_PROGRAM_NV, vspid, lightdir );

// c[4] now contains object space L vector.
// c[5] now contains object space H vector.
// c[8] now contains object space V vector.


// Enable the vertex program.
glBindProgramNV( GL_VERTEX_PROGRAM_NV, vpid );
glEnable( GL_VERTEX_PROGRAM_NV );

// Put the material color in register 6
glProgramParameter4fNV( GL_VERTEX_PROGRAM_NV, 6, 0.5, 0.7, 0.5, 1.0 );
// Put a (0,10,20,25) in register 7
glProgramParameter4fNV( GL_VERTEX_PROGRAM_NV, 7, 0.0, 10.0, 50.0, 100.0 );
// Put the light color in register 10
glProgramParameter4fNV( GL_VERTEX_PROGRAM_NV, 10, 0.7, 0.7, 1.0, 1.0 );

decaltex.bind();
decaltex.enable();

// Draw the quad.
glBegin( GL_QUADS );

glTexCoord2fv( &amp;(texuvdata[0].u) );
glNormal3fv( &amp;(normaldata[0].x) );
glVertex3fv( &amp;(vertexdata[0].x) );

glTexCoord2fv( &amp;(texuvdata[1].u) );
glNormal3fv( &amp;(normaldata[1].x) );
glVertex3fv( &amp;(vertexdata[1].x) );

glTexCoord2fv( &amp;(texuvdata[2].u) );
glNormal3fv( &amp;(normaldata[2].x) );
glVertex3fv( &amp;(vertexdata[2].x) );

glTexCoord2fv( &amp;(texuvdata[3].u) );
glNormal3fv( &amp;(normaldata[3].x) );
glVertex3fv( &amp;(vertexdata[3].x) );

glEnd();

decaltex.disable();

// Disable the vertex program.
glDisable( GL_VERTEX_PROGRAM_NV );

glutSwapBuffers();
}

void LOAD_VERTEX_PROGRAM( unsigned int _i, char *_n )
{
char *str = read_text_file( _n );
glBindProgramNV( GL_VERTEX_PROGRAM_NV, _i );
nvparse( str );
CheckParseErrors();
delete [] str;
}

void LOAD_VERTEX_STATE_PROGRAM( unsigned int _i, char *_n )
{
char *str = read_text_file( _n );
nvparse( str, _i );
CheckParseErrors();
delete [] str;
}

void init_opengl()
{
if( !glh_init_extensions( "GL_NV_vertex_program" ) )
{
cerr << "Necessary extensions were not supported:" << endl
<< glh_get_unsupported_extensions() << endl << endl
<< "Press <enter> to quit." << endl;
char buff[10];
cin.getline(buff, 10);
exit( -1 );
}

// Create the vertex program.
glGenProgramsNV( 1, &amp;vpid );
LOAD_VERTEX_PROGRAM( vpid, "vtxprg_litquad.vp" );

// Create the vertex state program that transforms the directional light into object space.
glGenProgramsNV( 1, &amp;vspid );
LOAD_VERTEX_STATE_PROGRAM( vspid, "vtxprg_litquad.vsp" );

// Track the concatenation of the modelview and projection matrix in registers 0-3.
glTrackMatrixNV( GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV );

// Track the modelview matrix in registers 12-15 for use by the vertex state program.
glTrackMatrixNV( GL_VERTEX_PROGRAM_NV, 12, GL_MODELVIEW, GL_INVERSE_NV );


decaltex.bind();
array2<vec3ub> decal_img;
read_png_rgb("rgb_gloss_map.png", decal_img);
make_rgb_texture( decal_img, true );
decaltex.parameter( GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
decaltex.parameter( GL_TEXTURE_MAG_FILTER, GL_LINEAR );

// Setup the blending state.
nvparse( "!!RC1.0 \n"
"out.rgb = tex0 * col0;\n" );
CheckParseErrors();

glClearColor( 0.67, 0.67, 0.67, 1.0 );
}

void keyboard( unsigned char k, int x, int y )
{
if ( k == 27 &amp;#0124; &amp;#0124; k == 'q' )
{
glDeleteProgramsNV( 1, &amp;vpid );
glDeleteProgramsNV( 1, &amp;vspid );
exit( 0 );
}
}

void idle()
{
object.trackball.increment_rotation();
glutPostRedisplay();
}


int main( int argc, char **argv )
{
glutInit( &amp;argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB );
glutInitWindowSize( 512, 512 );
glutInitWindowPosition( 256, 256 );
glutCreateWindow( "vtxprg_litquad" );

// Initialize the data for Quad.
InitializeQuadData();

// Do some OpenGL initialization.
init_opengl();

glut_helpers_initialize();

cb.keyboard_function = keyboard;
cb.idle_function = idle;
camera.configure_buttons(1);
camera.set_camera_mode(true);
camera.pan.pan = vec3f( 0.0, 0.0, 2.0 );
object.configure_buttons(1);
object.dolly.dolly[2] = -1;

glut_add_interactor(&amp;cb);
glut_add_interactor(&amp;object);
glut_add_interactor(&amp;reshaper);

glut_idle(1);

glutDisplayFunc( display );
glutMainLoop();
}


Diapolo

spiralsmile
12-10-2002, 07:58 AM
try here
http://www.chronos-central.com/

nehe type and very easy

yakuza
12-10-2002, 08:22 AM
Nutty has one on his site also, the last tutorial on this page:
http://opengl.nutty.org/extensions/index.html