예제 #1
0
/**
 * @brief Initialization on the rendering context. 
 */
void SetupRC()
{
	// Initialze Shader Manager
	shaderManager.InitializeStockShaders();

	glEnable(GL_DEPTH_TEST);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	// This makes a torus
	gltMakeSphere(sunSphereBatch, 0.4f, 30, 30);

	// This make a sphere
	gltMakeSphere(earthSphereBatch, 0.2f, 26, 13);

	// This make a small sphere
	gltMakeSphere(moonSphereBatch, 0.1, 18, 9);

	// Make the floor
	floorBatch.Begin(GL_LINES, 324);
	for(GLfloat x = -20.0; x <= 20.0f; x+= 0.5) 
	{
		floorBatch.Vertex3f(x, -0.55f, 20.0f);
		floorBatch.Vertex3f(x, -0.55f, -20.0f);

		floorBatch.Vertex3f(20.0f, -0.55f, x);
		floorBatch.Vertex3f(-20.0f, -0.55f, x);
	}
	floorBatch.End();    
}
예제 #2
0
// This function does any needed initialization on the rendering
// context. 
void SetupRC(void)
	{
	// Background
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

    shaderManager.InitializeStockShaders();
    viewFrame.MoveForward(4.0f);

    // Make the sphere
    gltMakeSphere(sphereBatch, 1.0f, 52, 26);

	normalMapShader = gltLoadShaderPairWithAttributes("NormalMapped\\NormalMapped.vp", "NormalMapped\\NormalMapped.fp", 3, GLT_ATTRIBUTE_VERTEX, "vVertex",
			GLT_ATTRIBUTE_NORMAL, "vNormal", GLT_ATTRIBUTE_TEXTURE0, "vTexture0");

	locAmbient = glGetUniformLocation(normalMapShader, "ambientColor");
	locDiffuse = glGetUniformLocation(normalMapShader, "diffuseColor");
	locLight = glGetUniformLocation(normalMapShader, "vLightPosition");
	locMVP = glGetUniformLocation(normalMapShader, "mvpMatrix");
	locMV  = glGetUniformLocation(normalMapShader, "mvMatrix");
	locNM  = glGetUniformLocation(normalMapShader, "normalMatrix");
	locColorMap = glGetUniformLocation(normalMapShader, "colorMap");
    locNormalMap = glGetUniformLocation(normalMapShader, "normalMap");

	glGenTextures(2, texture);
    glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	LoadTGATexture("NormalMapped\\IceMoon.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    LoadTGATexture("NormalMapped\\IceMoonBump.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT);
	}
예제 #3
0
//////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering
// context.
void SetupRC()
{
    // Make sure OpenGL entry points are set
    glewInit();
    
    // Initialze Shader Manager
    shaderManager.InitializeStockShaders();
    
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    
    // This makes a torus
    gltMakeTorus(torusBatch, 0.4f, 0.15f, 40, 20);
    
    // This makes a sphere
    gltMakeSphere(sphereBatch, 0.1f, 26, 13);
    
    
    // Make the solid ground
    GLfloat texSize = 10.0f;
    floorBatch.Begin(GL_TRIANGLE_FAN, 4, 1);
    floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
    floorBatch.Vertex3f(-20.0f, -0.41f, 20.0f);
    
    floorBatch.MultiTexCoord2f(0, texSize, 0.0f);
    floorBatch.Vertex3f(20.0f, -0.41f, 20.0f);
    
    floorBatch.MultiTexCoord2f(0, texSize, texSize);
    floorBatch.Vertex3f(20.0f, -0.41f, -20.0f);
    
    floorBatch.MultiTexCoord2f(0, 0.0f, texSize);
    floorBatch.Vertex3f(-20.0f, -0.41f, -20.0f);
    floorBatch.End();
    
    // Make 3 texture objects
    glGenTextures(3, uiTextures);
    
    // Load the Marble
    glBindTexture(GL_TEXTURE_2D, uiTextures[0]);
    LoadTGATexture("marble.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT);
    
    // Load Mars
    glBindTexture(GL_TEXTURE_2D, uiTextures[1]);
    LoadTGATexture("marslike.tga", GL_LINEAR_MIPMAP_LINEAR,
                   GL_LINEAR, GL_CLAMP_TO_EDGE);
    
    // Load Moon
    glBindTexture(GL_TEXTURE_2D, uiTextures[2]);
    LoadTGATexture("moonlike.tga", GL_LINEAR_MIPMAP_LINEAR,
                   GL_LINEAR, GL_CLAMP_TO_EDGE);
    
    // Randomly place the spheres
    for(int i = 0; i < NUM_SPHERES; i++) {
        GLfloat x = ((GLfloat)((rand() % 400) - 200) * 0.1f);
        GLfloat z = ((GLfloat)((rand() % 400) - 200) * 0.1f);
        spheres[i].SetOrigin(x, 0.0f, z);
    }
}
예제 #4
0
//////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering
// context. 
void SetupRC()
    {
	// Initialze Shader Manager
	shaderManager.InitializeStockShaders();
	
	glEnable(GL_DEPTH_TEST);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	
	// This makes a torus
	gltMakeTorus(torusBatch, 0.4f, 0.15f, 30, 30);
	
    // This make a sphere
    gltMakeSphere(sphereBatch, 0.1f, 26, 13);
    	
	floorBatch.Begin(GL_LINES, 324);
    for(GLfloat x = -20.0; x <= 20.0f; x+= 0.5) {
        floorBatch.Vertex3f(x, -0.55f, 20.0f);
        floorBatch.Vertex3f(x, -0.55f, -20.0f);
        
        floorBatch.Vertex3f(20.0f, -0.55f, x);
        floorBatch.Vertex3f(-20.0f, -0.55f, x);
        }
    floorBatch.End();    

    // Randomly place the spheres
    for(int i = 0; i < NUM_SPHERES; i++) {
        GLfloat x = ((GLfloat)((rand() % 400) - 200) * 0.1f);
        GLfloat z = ((GLfloat)((rand() % 400) - 200) * 0.1f);
        spheres[i].SetOrigin(x, 0.0f, z);
        }
    }
예제 #5
0
// This function does any needed initialization on the rendering
// context. 
void SetupRC(void)
	{
	// Background
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

    shaderManager.InitializeStockShaders();
    viewFrame.MoveForward(4.0f);

    // Make the sphere
    gltMakeSphere(sphereBatch, 1.0f, 26, 13);

	ADSLightShader = shaderManager.LoadShaderPairWithAttributes("ADSGouraud.vp", "ADSGouraud.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex",
			GLT_ATTRIBUTE_NORMAL, "vNormal");

	locAmbient = glGetUniformLocation(ADSLightShader, "ambientColor");
	locDiffuse = glGetUniformLocation(ADSLightShader, "diffuseColor");
	locSpecular = glGetUniformLocation(ADSLightShader, "specularColor");
	locLight = glGetUniformLocation(ADSLightShader, "vLightPosition");
	locMVP = glGetUniformLocation(ADSLightShader, "mvpMatrix");
	locMV  = glGetUniformLocation(ADSLightShader, "mvMatrix");
	locNM  = glGetUniformLocation(ADSLightShader, "normalMatrix");
	}
예제 #6
0
void SetupRC(void)
{
	shaderManager.InitializeStockShaders();

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	gltMakeSphere(sphereBatch, 0.2f, 26, 13);

	gltMakeTorus(torusBatch, 0.4f, 0.15f, 30, 30);

	for (size_t i = 0; i < NUM_SPHERES; ++i)
	{
		float x = (GLfloat(rand() % 400) - 200.0f) * 0.1f;
		float z = (GLfloat(rand() % 400) - 200.0f) * 0.1f;
		sphereFrames[i].SetOrigin(x, 0.0f, z);
	}
	

	//Make the solid ground
	GLfloat texSize = 10.0f;

	floorBatch.Begin(GL_TRIANGLE_FAN, 4,1);
	{
		//没看懂纹理和顶点的映射关系
		floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
		floorBatch.Vertex3f(-20.0f, -0.41f, 20.0f);

		floorBatch.MultiTexCoord2f(0, texSize, 0.0f);
		floorBatch.Vertex3f(20.0f, -0.41f, 20.0f);

		floorBatch.MultiTexCoord2f(0, texSize, texSize);
		floorBatch.Vertex3f(20.0f, -0.41f, -20.0f);

		floorBatch.MultiTexCoord2f(0, 0.0f, texSize);
		floorBatch.Vertex3f(-20.0f, -0.41f, -20.0f);
	}
	floorBatch.End();

	// Make 3 texture objects
	glGenTextures(3, uiTextures);

	// Load the Marble
	glBindTexture(GL_TEXTURE_2D, uiTextures[0]);
	LoadTGATexture("marble.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT);

	// Load Mars
	glBindTexture(GL_TEXTURE_2D, uiTextures[1]);
	LoadTGATexture("marslike.tga", GL_LINEAR_MIPMAP_LINEAR,
		GL_LINEAR, GL_CLAMP_TO_EDGE);

	// Load Moon
	glBindTexture(GL_TEXTURE_2D, uiTextures[2]);
	LoadTGATexture("moonlike.tga", GL_LINEAR_MIPMAP_LINEAR,
		GL_LINEAR, GL_CLAMP_TO_EDGE);
}
예제 #7
0
//////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering
// context. 
void SetupRC()
    {
    GLbyte *pBytes;
    GLint iWidth, iHeight, iComponents;
    GLenum eFormat;
    int i;
       
    // Cull backs of polygons
    glCullFace(GL_BACK);
    glFrontFace(GL_CCW);
    glEnable(GL_DEPTH_TEST);
        
    glGenTextures(1, &cubeTexture);
    glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTexture);
        
    // Set up texture maps        
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);       
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        
  
    // Load Cube Map images
    for(i = 0; i < 6; i++)
        {        
        // Load this texture map
        pBytes = gltReadTGABits(szCubeFaces[i], &iWidth, &iHeight, &iComponents, &eFormat);
        glTexImage2D(cube[i], 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytes);
        free(pBytes);
        }
    glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
    
    viewFrame.MoveForward(-4.0f);
    gltMakeSphere(sphereBatch, 1.0f, 52, 26);
    gltMakeCube(cubeBatch, 20.0f);
    
    reflectionShader = gltLoadShaderPairWithAttributes("Reflection.vp", "Reflection.fp", 2, 
                                                GLT_ATTRIBUTE_VERTEX, "vVertex",
                                                GLT_ATTRIBUTE_NORMAL, "vNormal");
                                                
    locMVPReflect = glGetUniformLocation(reflectionShader, "mvpMatrix");
    locMVReflect = glGetUniformLocation(reflectionShader, "mvMatrix");
    locNormalReflect = glGetUniformLocation(reflectionShader, "normalMatrix");
	locInvertedCamera = glGetUniformLocation(reflectionShader, "mInverseCamera");
                                                
                                                
    skyBoxShader = gltLoadShaderPairWithAttributes("SkyBox.vp", "SkyBox.fp", 2, 
                                                GLT_ATTRIBUTE_VERTEX, "vVertex",
                                                GLT_ATTRIBUTE_NORMAL, "vNormal");

	locMVPSkyBox = glGetUniformLocation(skyBoxShader, "mvpMatrix");

    
    }
예제 #8
0
void Gripper::setup(){
	phidgets.start();

	gltMakeSphere(sphereBatch, 1, 18, 18);
	gltMakeCylinder(cylBatch, 1, 1, 1, 18, 2);

	for(int i = 0; i < YELLOW; ++i){
		offsets[i][0] = offsets[i][1] = offsets[i][2] = 0;
	}

	for(int i = 0; i < NUM_END_EFFECTORS; ++i){
		endEffector[i].minRaw = 410;
		endEffector[i].maxRaw = 480;
		endEffector[i].scalar = .3;
		endEffector[i].gripperForce = 0;
		endEffector[i].restoreForce = 0.4;
		endEffector[i].minRange = 1.0;
		endEffector[i].maxRange = 4.0;
		endEffector[i].curPos = 4.0;
		endEffector[i].contactForce = 0;
	}

}
예제 #9
0
파일: main.cpp 프로젝트: wdlove58/WcgCube
void SetupRC()
{
	glClearColor(0, 0, 0, 1);

	shaderManager.InitializeStockShaders();
	
	glEnable(GL_DEPTH_TEST);

	gltMakeSphere(sphereBatch, 0.4, 20, 20);
	gltMakeCube(cubeBatch, 0.3);

	// Load up a triangle
	GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 
		0.5f, 0.0f, 0.0f,
		0.0f, 0.5f, 0.0f };

	GLfloat vColors [] = { 1.0f, 0.0f, 0.0f, 1.0f,
		0.0f, 1.0f, 0.0f, 1.0f,
		0.0f, 0.0f, 1.0f, 1.0f };

	triangleBatch.Begin(GL_TRIANGLES, 3);
	triangleBatch.CopyVertexData3f(vVerts);
	triangleBatch.CopyColorData4f(vColors);
	triangleBatch.End();
	
	mWcgCube.SetupCube();

	/*transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);*/
	cameraFrame.MoveForward(-3.0f);

	m3dLoadIdentity44(mRotation);
	
	myShader = gltLoadShaderPairWithAttributes("shader.vp", "shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", 
												GLT_ATTRIBUTE_COLOR, "vColor");
	locMVP = glGetUniformLocation(myShader, "mvpMatrix");
}
예제 #10
0
void SetupRC(void)
{
	// Make sure OpenGL entry points are set
	//glewInit();

	shaderManager.InitializeStockShaders();

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	gltMakeTorus(torusBatch, 0.3f, 0.1f, 52, 26);
	gltMakeSphere(sphereBatch, 0.1f, 26, 13);

	//make the solid ground
	GLfloat texSize = 10.0f;
	floorBatch.Begin(GL_TRIANGLE_FAN,4,1);
	floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
	floorBatch.Vertex3f(-20.f, -0.41f, 20.f);

	floorBatch.MultiTexCoord2f(0, texSize, 0.0f);
	floorBatch.Vertex3f(20.f, -0.41f, 20.f);

	floorBatch.MultiTexCoord2f(0, texSize, texSize);
	floorBatch.Vertex3f(20.f, -0.41f, -20.f);

	floorBatch.MultiTexCoord2f(0, 0.0f, texSize);
	floorBatch.Vertex3f(-20.f, -0.41f, -20.f);

	floorBatch.End();

	int x = 400;
	int y = 200;
	int width = 300;
	int height = 155;
	logoBatch.Begin(GL_TRIANGLE_FAN, 4, 1);
//像素点的原点是左上角, 根据GL_TRIANGLE_FAN 做了调整

	// Upper left hand corner
	logoBatch.MultiTexCoord2f(0, 0.0f, height);
	logoBatch.Vertex3f(x, y, 0.0f);

	logoBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
	logoBatch.Vertex3f(x, y - height, 0.0f);

	// Lower right hand corner
	logoBatch.MultiTexCoord2f(0, width, 0.0f);
	logoBatch.Vertex3f(x + width, y - height, 0.0f);

	// Upper righ hand corner
	logoBatch.MultiTexCoord2f(0, width, height);
	logoBatch.Vertex3f(x + width, y, 0.0f);

	logoBatch.End();

	glGenTextures(4, uiTextures);

	// Load the Marble
	glBindTexture(GL_TEXTURE_2D, uiTextures[0]);
	LoadTGATexture("marble.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT);

	// Load Mars
	glBindTexture(GL_TEXTURE_2D, uiTextures[1]);
	LoadTGATexture("marslike.tga", GL_LINEAR_MIPMAP_LINEAR,
		GL_LINEAR, GL_CLAMP_TO_EDGE);

	// Load Moon
	glBindTexture(GL_TEXTURE_2D, uiTextures[2]);
	LoadTGATexture("moonlike.tga", GL_LINEAR_MIPMAP_LINEAR,
		GL_LINEAR, GL_CLAMP_TO_EDGE);

	// Load the Logo
	glBindTexture(GL_TEXTURE_RECTANGLE, uiTextures[3]);
	LoadTGATextureRect("OpenGL-Logo.tga", GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE);

	sphereWolrdShader = gltLoadShaderPairWithAttributes("RectReplace.vp", "RectReplace.fp",
		2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_TEXTURE0, "vTexCoord");
	
	locMVP = glGetUniformLocation(sphereWolrdShader, "mvpMatrix");
	locTexture = glGetUniformLocation(sphereWolrdShader, "rectangleImage");


	// -200,200
	// Randomly place the spheres
	for (int i = 0; i < NUM_SPHERES; i++) 
	{
		GLfloat x = ((GLfloat)((rand() % 400) - 200) * 0.1f);
		GLfloat z = ((GLfloat)((rand() % 400) - 200) * 0.1f);
		spheres[i].SetOrigin(x, 0.0f, z);
	}
}
void Renderer::initializeGL() {
    gltSetWorkingDirectory("");
    GLenum err = glewInit();
    if (GLEW_OK != err) {
        qWarning()<<"GLEW Error: "<<glewGetErrorString(err);
    }

  /*  glClearColor(0, 0, 0, 0);
    this->resizeGL( parentWidget()->size() );

    mCameraFrame.MoveForward(-4.0);

    mShaderManager.InitializeStockShaders();

    glEnable(GL_DEPTH_TEST);
    glClearColor(0.2,0.2,0.2,1.0f);

//   glEnable(GL_LIGHTING);
//    glEnable(GL_NORMALIZE);
//    glEnable(GL_DEPTH_TEST);
//    glEnable(GL_COLOR_MATERIAL);
//    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);

//    glShadeModel(GL_SMOOTH);

//    glEnable(GL_LIGHTING);
//    glEnable(GL_LIGHT0);
//    glLightfv(GL_LIGHT0, GL_AMBIENT, gLight0[0]);
//    glLightfv(GL_LIGHT0, GL_DIFFUSE, gLight0[1]);
//    glLightfv(GL_LIGHT0, GL_POSITION, gLight0[2]);

//    glEnable(GL_LIGHT1);
//    glLightfv(GL_LIGHT1, GL_AMBIENT, gLight1[0]);
//    glLightfv(GL_LIGHT1, GL_DIFFUSE, gLight1[1]);
//    glLightfv(GL_LIGHT1, GL_POSITION, gLight1[2]);

//    glEnable(GL_CULL_FACE);
//    glCullFace(GL_FRONT_AND_BACK);

//    mCameraFrame.SetForwardVector(0,0,1);
//    mCameraFrame.SetUpVector(0,1,0);
//    mCameraFrame.SetOrigin(0,0,0);


    glEnable(GL_CULL_FACE);
    glCullFace(GL_FRONT_AND_BACK);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnableClientState(GLT_ATTRIBUTE_VERTEX);

    gltMakeSphere(sphereBatch, 1.3f, 15, 15);*/



    // Initialze Shader Manager
    mShaderManager.InitializeStockShaders();
    gltMakeSphere(sphereBatch, 0.3f, 15, 15);

    glEnable(GL_DEPTH_TEST);
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
///////////////////////////////////////////////////////////////////////////////
// OpenGL related startup code is safe to put here. Load textures, etc.
void SetupRC()
{
#ifndef ANGLE
    GLenum err = glewInit();
	if (GLEW_OK != err)
	{
		/* Problem: glewInit failed, something is seriously wrong. */
		fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
	}
#endif

	// Initialze Shader Manager
	shaderManager.InitializeStockShaders();

	glEnable(GL_DEPTH_TEST);

	// Black
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

#if defined __APPLE__ || defined ANGLE
    ninja.LoadFromSBM("ninja.sbm",
                      GLT_ATTRIBUTE_VERTEX,
                      GLT_ATTRIBUTE_NORMAL,
                      GLT_ATTRIBUTE_TEXTURE0);    
#else
    ninja.LoadFromSBM("../../../Src/Models/Ninja/ninja.sbm",
        GLT_ATTRIBUTE_VERTEX,
        GLT_ATTRIBUTE_NORMAL,
        GLT_ATTRIBUTE_TEXTURE0);
#endif
	gltMakeTorus(torusBatch, 0.4f, 0.15f, 35, 35);
	gltMakeSphere(sphereBatch, 0.1f, 26, 13);

	GLfloat alpha = 0.25f;
	floorBatch.Begin(GL_TRIANGLE_FAN, 4, 1);
		floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha);
		floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
		floorBatch.Normal3f(0.0, 1.0f, 0.0f);
		floorBatch.Vertex3f(-20.0f, -0.41f, 20.0f);

		floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha);
		floorBatch.MultiTexCoord2f(0, 10.0f, 0.0f);
		floorBatch.Normal3f(0.0, 1.0f, 0.0f);
		floorBatch.Vertex3f(20.0f, -0.41f, 20.0f);

		floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha);
		floorBatch.MultiTexCoord2f(0, 10.0f, 10.0f);
		floorBatch.Normal3f(0.0, 1.0f, 0.0f);
		floorBatch.Vertex3f(20.0f, -0.41f, -20.0f);

		floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha);
		floorBatch.MultiTexCoord2f(0, 0.0f, 10.0f);
		floorBatch.Normal3f(0.0, 1.0f, 0.0f);
		floorBatch.Vertex3f(-20.0f, -0.41f, -20.0f);
	floorBatch.End();

	glGenTextures(1, textures);
	glBindTexture(GL_TEXTURE_2D, textures[0]);
	LoadBMPTexture("marble.bmp", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT);

    glGenTextures(1, ninjaTex);
	glBindTexture(GL_TEXTURE_2D, ninjaTex[0]);
#if defined __APPLE__
	LoadBMPTexture("NinjaComp.bmp", GL_LINEAR, GL_LINEAR, GL_CLAMP);
#elif defined ANGLE
	LoadBMPTexture("NinjaComp.bmp", GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
#else
	LoadBMPTexture("../../../Src/Models/Ninja/NinjaComp.bmp", GL_LINEAR, GL_LINEAR, GL_CLAMP);
#endif

	glGenFramebuffers(1,&fboName);

	// Create depth renderbuffer
	glGenRenderbuffers(1, &depthBufferName);
	glBindRenderbuffer(GL_RENDERBUFFER, depthBufferName);
#ifndef ANGLE
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, screenWidth, screenHeight);
#else
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, screenWidth, screenHeight);
#endif

	// Create 3 color renderbuffers
	glGenRenderbuffers(3, renderBufferNames);
	glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[0]);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight);
	glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[1]);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight);
	glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[2]);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight);

	// Attach all 4 renderbuffers to FBO
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName);
	glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBufferName);
	glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderBufferNames[0]);
#ifndef OPENGL_ES
	glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, renderBufferNames[1]);
	glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, renderBufferNames[2]);
#endif

	// See bind frag location in Chapter 9
    processProg =  gltLoadShaderPairWithAttributes("multibuffer.vs", "multibuffer_frag_location.fs", 3,
								GLT_ATTRIBUTE_VERTEX, "vVertex", 
								GLT_ATTRIBUTE_NORMAL, "vNormal", 
								GLT_ATTRIBUTE_TEXTURE0, "texCoord0");
#ifndef OPENGL_ES
	glBindFragDataLocation(processProg, 0, "oStraightColor");
	glBindFragDataLocation(processProg, 1, "oGreyscale");
	glBindFragDataLocation(processProg, 2, "oLumAdjColor"); 
#endif
	glLinkProgram(processProg);

#ifndef OPENGL_ES
	// Create 3 new buffer objects
	glGenBuffers(3,texBO);
	glGenTextures(1, &texBOTexture);
	
	int count = 0;
	float* fileData = 0;

	// Load first texBO with a tangent-like curve, 1024 values
	fileData = LoadFloatData("LumTan.data", &count);
	if (count > 0)
	{
		glBindBuffer(GL_TEXTURE_BUFFER_ARB, texBO[0]);
		glBufferData(GL_TEXTURE_BUFFER_ARB, sizeof(float)*count, fileData, GL_STATIC_DRAW);
		delete fileData;
	}

	// Load second texBO with a sine-like curve, 1024 values
	fileData = LoadFloatData("LumSin.data", &count);
	if (count > 0)
	{
		glBindBuffer(GL_TEXTURE_BUFFER_ARB, texBO[1]);
		glBufferData(GL_TEXTURE_BUFFER_ARB, sizeof(float)*count, fileData, GL_STATIC_DRAW);
		delete fileData;
	}

	// Load third texBO with a linear curve, 1024 values
	fileData = LoadFloatData("LumLinear.data", &count);
	if (count > 0)
	{
		glBindBuffer(GL_TEXTURE_BUFFER_ARB, texBO[2]);
		glBufferData(GL_TEXTURE_BUFFER_ARB, sizeof(float)*count, fileData, GL_STATIC_DRAW);
		delete fileData;
	}

	// Load the Tan ramp first
	glBindBuffer(GL_TEXTURE_BUFFER_ARB, 0);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_BUFFER_ARB, texBOTexture);
	glTexBufferARB(GL_TEXTURE_BUFFER_ARB, GL_R32F, texBO[0]); 
#endif
	glActiveTexture(GL_TEXTURE0);

	// Reset framebuffer binding
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

	// Make sure all went well
	gltCheckErrors();
}
예제 #13
0
///////////////////////////////////////////////////////////////////////////////
// OpenGL related startup code is safe to put here. Load textures, etc.
void SetupRC()
{
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
    }
    
    // Initialze Shader Manager
    shaderManager.InitializeStockShaders();
    glEnable(GL_DEPTH_TEST);
    
    // Black
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    
    gltMakeTorus(torusBatch, 0.4f, 0.15f, 35, 35);
    gltMakeSphere(sphereBatch, 0.1f, 26, 13);
    gltMakeCylinder(cylinderBatch,0.3f, 0.2f, 1.0, 10,10);
    
    GLfloat alpha = 0.25f;
    floorBatch.Begin(GL_TRIANGLE_FAN, 4, 1);
    floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha);
    floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
    floorBatch.Normal3f(0.0, 1.0f, 0.0f);
    floorBatch.Vertex3f(-20.0f, -0.41f, 20.0f);
    
    floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha);
    floorBatch.MultiTexCoord2f(0, 10.0f, 0.0f);
    floorBatch.Normal3f(0.0, 1.0f, 0.0f);
    floorBatch.Vertex3f(20.0f, -0.41f, 20.0f);
    
    floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha);
    floorBatch.MultiTexCoord2f(0, 10.0f, 10.0f);
    floorBatch.Normal3f(0.0, 1.0f, 0.0f);
    floorBatch.Vertex3f(20.0f, -0.41f, -20.0f);
    
    floorBatch.Color4f(0.0f, 1.0f, 0.0f, alpha);
    floorBatch.MultiTexCoord2f(0, 0.0f, 10.0f);
    floorBatch.Normal3f(0.0, 1.0f, 0.0f);
    floorBatch.Vertex3f(-20.0f, -0.41f, -20.0f);
    floorBatch.End();
    
    mirrorBatch.Begin(GL_TRIANGLE_FAN, 4, 1);
    mirrorBatch.Color4f(1.0f, 0.0f, 0.0f, 1.0f);
    mirrorBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
    mirrorBatch.Normal3f( 0.0f, 1.0f, 0.0f);
    mirrorBatch.Vertex3f(-1.0f, 0.0f, 0.0f);
    
    mirrorBatch.Color4f(1.0f, 0.0f, 0.0f, 1.0f);
    mirrorBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
    mirrorBatch.Normal3f(0.0f, 1.0f, 0.0f);
    mirrorBatch.Vertex3f(1.0f, 0.0f, 0.0f);
    
    mirrorBatch.Color4f(1.0f, 0.0f, 0.0f, 1.0f);
    mirrorBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
    mirrorBatch.Normal3f(0.0f, 1.0f, 0.0f);
    mirrorBatch.Vertex3f(1.0f, 2.0f, 0.0f);
    
    mirrorBatch.Color4f(1.0f, 0.0f, 0.0f, 1.0f);
    mirrorBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
    mirrorBatch.Normal3f( 0.0f, 1.0f, 0.0f);
    mirrorBatch.Vertex3f(-1.0f, 2.0f, 0.0f);
    mirrorBatch.End();
    
    mirrorBorderBatch.Begin(GL_TRIANGLE_STRIP, 13);
    mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(-1.0f, 0.1f, 0.01f);
    
    mirrorBorderBatch.Normal3f(0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(-1.0f, 0.0f, 0.01f);
    
    mirrorBorderBatch.Normal3f(0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(1.0f, 0.1f, 0.01f);
    
    mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(1.0f, 0.0f, 0.01f);
    
    mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(0.9f, 0.0f, 0.01f);
    
    mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(1.0f, 2.0f, 0.01f);
    
    mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(0.9f, 2.0f, 0.01f);
    
    mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(1.0f, 1.9f, 0.01f);
    
    mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(-1.0f, 2.f, 0.01f);
    
    mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(-1.0f, 1.9f, 0.01f);
    
    mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(-0.9f, 2.f, 0.01f);
    
    mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(-1.0f, 0.0f, 0.01f);
    
    mirrorBorderBatch.Normal3f( 0.0f, 0.0f, 1.0f);
    mirrorBorderBatch.Vertex3f(-0.9f, 0.0f, 0.01f);
    mirrorBorderBatch.End();
    
    glGenTextures(1, textures);
    glBindTexture(GL_TEXTURE_2D, textures[0]);
    LoadBMPTexture("marble.bmp", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT);
    
    // Create and bind an FBO
    glGenFramebuffers(1,&fboName);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName);
    
    // Create depth renderbuffer
    glGenRenderbuffers(1, &depthBufferName);
    glBindRenderbuffer(GL_RENDERBUFFER, depthBufferName);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, mirrorTexWidth, mirrorTexHeight);
    
    // Create the reflection texture
    glGenTextures(1, &mirrorTexture);
    glBindTexture(GL_TEXTURE_2D, mirrorTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mirrorTexWidth, mirrorTexHeight, 0, GL_RGBA, GL_FLOAT, NULL);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    
    // Attach texture to first color attachment and the depth RBO
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mirrorTexture, 0);
    glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBufferName);
    
    // Make sure all went well
    gltCheckErrors();
    
    // Reset framebuffer binding
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
예제 #14
0
void initTriangleBatch()
{
    gltMakeTorus(torusBatch,1.0f,0.5f,50,25);
    gltMakeSphere(sphereBatch,0.3,32,32);
    gltMakeCylinder(cylinderBatch,1.0,0.5,1.0,16,32);
}