Jump to content
  • Advertisement
Sign in to follow this  
judge dreadz

Please look at this Cg shader

This topic is 4826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, i'm just starting out trying to learn Cg. Here is the shader i wrote:
struct vShader1Out {
	float4 position : POSITION;
	float4 color	: COLOR;

vShader1Out vShader1(float2 position : POSITION)
	vShader1Out OUT;
	OUT.position = float4(position, 0, 1);
	OUT.color    = float4(1, 0, 0, 1);
	return OUT;

This is basically the same as the first shader from the Cg tutorial book. I draw a square in openGL, and then pass the position paramater to the shader. I expected only the color of the square to be changed to red, but when i run it the square is a different size and in a different place. does anyone know whats causing this? Here is the openGL code i wrote:
#include <GL/glut.h>
#include <GL/gl.h>
#include <Cg/cg.h>      
#include <Cg/cgGL.h>    

CGcontext cgContext;
CGprogram vShader;
CGparameter positionParam;

CGprofile vProfile = CG_PROFILE_VP20;

void display(void)
        glVertex2f(0.25, 0.25);
        glVertex2f(0.75, 0.25);
        glVertex2f(0.75, 0.75);
        glVertex2f(0.25, 0.75);

void init(void)
    // initialise GL
    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

    // initialise Cg
    cgContext = cgCreateContext();
    vShader = cgCreateProgramFromFile(cgContext, CG_SOURCE, "vShader1.cg", vProfile, "vShader1", NULL);    
    cgGLLoadProgram(vShader);   // load vertex shader
    positionParam = cgGetNamedParameter(vShader, "position");

int main(int argc, char** argv)
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(400, 300);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("My Cg Shader");
    // Release shaders once main drawing loop has stopped running

    return 0;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!