   Importing vertex data into a CG shader.
  I don't understand how to import all the vertex data I need in to a CG shader.Here is my shader:[Source]struct VS_OUTPUT{float4 position : POSITION;float4 color: COLOR;   float2 tex : TEXCOORD0;};struct PS_INPUT{float4 color: COLOR;   float2 tex : TEXCOORD0;};VS_OUTPUT VS(float3 position : POSITION, float4 weights : BLENDWEIGHT, float4 index : BLENDINDICES, float3 normal : NORMAL, float2 tex : TEXCOORD0, uniform float4x4 ModelViewProj){VS_OUTPUT OUT;OUT.position = mul(ModelViewProj, float4(position,1));OUT.tex = tex;return OUT;}float4 PS(PS_INPUT IN, uniform sampler2D Tex0) : COLOR{return tex2D( Tex0, IN.tex );}And here is my program though I know it looks like allot of code to look at but it's really simple all it does is render a triangle with a shader:#include <windows.h>#include <stdio.h>#include <gl\glew.h>#include <gl\gl.h>#include <gl\glu.h>#include <cg\cg.h>#include <cg\cgGL.h>HWND  hWnd=NULL;HGLRC hRC=NULL;HDC   hDC=NULL;boolkeys[256];CGcontext cgContext;CGprogram cg_vs, cg_ps;CGprofile cgVertexProfile, cgPixelProfile;CGparameter position, color, modelViewMatrix;CGparameter  Tex0;GLuint  vertex_buffer, index_buffer;GLuint texture[1];struct E_VECTOR{float x, y, z;};struct E_VERTEX{float x, y, z;float weight[4];float indices[4];float nx, ny, nz;float tu, tv;};struct E_KEY{DWORD t;float x, y, z;};struct E_BONE{E_VECTOR  offset;BYTE childen[256];E_KEY *poskeys;E_KEY *rotkeys;E_KEY *scalekeys;};LRESULTCALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);GLvoid GLResize(GLsizei width, GLsizei height){if(height==0)height=1;glViewport(0,0,width,height);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}GLuint LoadTextureRAW( const char * filename ){    GLuint texture;    int width, height;    BYTE * data;    FILE * file;    file = fopen( filename, "rb" );    if ( file == NULL ) return 0;    width = 256;    height = 256;    data = new BYTE[width * height * 4];    fread( data, width * height * 4, 1, file );    fclose( file );    glGenTextures( 1, &texture );    glBindTexture( GL_TEXTURE_2D, texture );    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST );    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT);    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);    gluBuild2DMipmaps( GL_TEXTURE_2D, 4, width, height,GL_RGBA, GL_UNSIGNED_BYTE, data );    delete [] data;    return texture;}void load_mesh(){E_VERTEX* vertices = new E_VERTEX[3];vertices[0].x=0;vertices[0].y=0;vertices[0].z=0;vertices[1].x=10;vertices[1].y=0;vertices[1].z=0;vertices[1].tu=1;vertices[2].x=0;vertices[2].y=10;vertices[2].z=0;vertices[2].tv=1;int* indices = new int[3];indices[0]=2;indices[1]=1;indices[2]=0;glGenBuffers( 1, &vertex_buffer );glBindBuffer( GL_ARRAY_BUFFER, vertex_buffer );glBufferData( GL_ARRAY_BUFFER, 3*sizeof(E_VERTEX), vertices, GL_STATIC_DRAW );glGenBuffers( 1, &index_buffer );glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, index_buffer );glBufferData( GL_ELEMENT_ARRAY_BUFFER, 3*sizeof(int), indices, GL_STATIC_DRAW );delete [] vertices;delete [] indices;}void render(){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();gluLookAt(0.0f, 25.0f, -45.0f, 0.0f, 0.0f, 0.0f, 0, 1, 0);cgGLSetStateMatrixParameter(modelViewMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);    cgGLSetTextureParameter( Tex0, texture[0] );cgGLEnableProfile(cgVertexProfile);cgGLBindProgram(cg_vs);cgGLEnableProfile(cgPixelProfile);cgGLBindProgram(cg_ps);cgGLEnableTextureParameter( Tex0 );glEnableClientState( GL_VERTEX_ARRAY );glBindBuffer( GL_ARRAY_BUFFER, vertex_buffer );glVertexPointer( 3, GL_FLOAT, sizeof(E_VERTEX), 0);glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, index_buffer );glDrawElements(GL_TRIANGLES,3,GL_UNSIGNED_SHORT,0);glDisableClientState( GL_VERTEX_ARRAY );cgGLDisableTextureParameter( Tex0 );cgGLDisableProfile(cgPixelProfile);cgGLDisableProfile(cgVertexProfile);SwapBuffers(hDC);}LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){switch (uMsg){case WM_CLOSE:{PostQuitMessage(0);return 0;}case WM_KEYDOWN:{keys[wParam] = TRUE;return 0;}case WM_KEYUP:{keys[wParam] = FALSE;return 0;}case WM_CREATE:{GLResize(LOWORD(lParam),HIWORD(lParam));return 0;}case WM_SIZE:{GLResize(LOWORD(lParam),HIWORD(lParam));return 0;}}return DefWindowProc(hWnd,uMsg,wParam,lParam);}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ){RECTWindowRect;WindowRect.left=0;WindowRect.right=640;WindowRect.top=0;WindowRect.bottom=480;WNDCLASSwc;wc.style= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;wc.lpfnWndProc= (WNDPROC) WndProc;wc.cbClsExtra= 0;wc.cbWndExtra= 0;wc.hInstance= 0;wc.hIcon= LoadIcon(NULL, IDI_WINLOGO);wc.hCursor= LoadCursor(NULL, IDC_ARROW);wc.hbrBackground= 0;wc.lpszMenuName= 0;wc.lpszClassName= "Debug";RegisterClass(&wc);hWnd = CreateWindowEx( WS_EX_APPWINDOW  | WS_EX_WINDOWEDGE, "Debug", "Debug" ,WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WindowRect.left, WindowRect.top, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, 0, 0, 0, 0);ShowWindow(hWnd,SW_SHOW);UnregisterClass( "Debug", wc.hInstance );static PIXELFORMATDESCRIPTOR pfd={ sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |PFD_DOUBLEBUFFER,PFD_TYPE_RGBA, 16,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 };hDC=GetDC(hWnd);SetPixelFormat(hDC,ChoosePixelFormat(hDC,&pfd),&pfd);hRC = wglCreateContext(hDC);wglMakeCurrent(hDC,hRC);glShadeModel(GL_SMOOTH);glClearColor(1.0f, 0.0f, 0.0f, 0.0f);glClearDepth(1.0f);glEnable(GL_DEPTH_TEST);glDepthFunc(GL_LEQUAL);glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);cgContext = cgCreateContext();cgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);cgPixelProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);cg_vs = cgCreateProgramFromFile(cgContext, CG_SOURCE, "Data/Shaders/default.cg", cgVertexProfile, "VS", 0);cgGLLoadProgram(cg_vs);cg_ps = cgCreateProgramFromFile(cgContext, CG_SOURCE, "Data/Shaders/default.cg", cgPixelProfile, "PS", 0);cgGLLoadProgram(cg_ps);modelViewMatrix= cgGetNamedParameter(cg_vs, "ModelViewProj");Tex0  = cgGetNamedParameter(cg_ps, "Tex0");GLResize(WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top);glewInit();load_mesh();texture[0]=LoadTextureRAW( "u3.raw");MSG msg;ZeroMemory( &msg, sizeof( msg ) );while( msg.message!=WM_QUIT ){if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ){TranslateMessage( &msg );DispatchMessage( &msg );}elserender();}wglMakeCurrent(NULL,NULL);wglDeleteContext(hRC);hRC=NULL;return (msg.wParam);}[Edited by - EmptyVoid on August 14, 2008 4:51:20 AM]
  So what is missing your normals, texCoords, ect...? You don't upload any data to the related pointer. All I see is glVertexPointer() nothing for texCoordinates, normals, ect.... So all you should be seeing is the vertices.   ;Quote:Original post by MARS_999So what is missing your normals, texCoords, ect...? You don't upload any data to the related pointer. All I see is glVertexPointer() nothing for texCoordinates, normals, ect.... So all you should be seeing is the vertices.Oh I got it now! But one thing, what command would be used to upload weights and bone indices?   ;  I don't think I'm doing it right, I can't even get the texture coordinates to work.void render(){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();gluLookAt(0.0f, 25.0f, -45.0f, 0.0f, 0.0f, 0.0f, 0, 1, 0);cgGLSetStateMatrixParameter(modelViewMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);    cgGLSetTextureParameter( Tex0, texture[0] );cgGLEnableProfile(cgVertexProfile);cgGLBindProgram(cg_vs);cgGLEnableProfile(cgPixelProfile);cgGLBindProgram(cg_ps);cgGLEnableTextureParameter( Tex0 );glBindBuffer( GL_ARRAY_BUFFER, vertex_buffer );glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, index_buffer );glEnableClientState( GL_VERTEX_ARRAY );glEnableClientState (GL_TEXTURE_COORD_ARRAY);glVertexPointer( 3, GL_FLOAT, sizeof(E_VERTEX), 0);glTexCoordPointer( 2, GL_FLOAT, sizeof(E_VERTEX), (GLvoid *)(sizeof(float)*14));glDrawElements(GL_TRIANGLES,3,GL_UNSIGNED_SHORT,0);glDisableClientState( GL_VERTEX_ARRAY );glDisableClientState( GL_TEXTURE_COORD_ARRAY );cgGLDisableTextureParameter( Tex0 );cgGLDisableProfile(cgPixelProfile);cgGLDisableProfile(cgVertexProfile);SwapBuffers(hDC);} [Edited by - EmptyVoid on August 8, 2008 6:22:47 PM];  Can someone just look over the code in my last post and tell me what I did wrong because it's driving me crazy!   ;  What does this function do?cgGLSetTextureParameter( Tex0, texture[0] );Have you called cgSetSamplerState?Have you called glGetError?   ;Quote:Original post by V-manWhat does this function do?cgGLSetTextureParameter( Tex0, texture[0] );Have you called cgSetSamplerState?Have you called glGetError?cgGLSetTextureParameter sets the texture which I know is working fine because I see the texture but the coordinates are all zero and glGetError returns no errors but I don't even know what cgSetSamplerState is for?;  I got to bump this. It's been 4 days that I've been trying to figure this out and I'm running out of time to work on it. I have a feeling it's something stupid but I just can't see it...   ;  I would like to help, but never used Cg, if you used GLSL I could help you out! ;)From the looks of it you aren't uploading the data to Cg, and if you are interleaving you need to make sure you are making your memory offsets correctly, if you are using VBOs.   ;Quote:Original post by MARS_999I would like to help, but never used Cg, if you used GLSL I could help you out! ;)From the looks of it you aren't uploading the data to Cg, and if you are interleaving you need to make sure you are making your memory offsets correctly, if you are using VBOs.Well could you show me some code that uploads the vertex data during rendering in GLSL? It may help me understand...   