예제 #1
0
// ============================================================================
Teuchos::RCP<Recti::Domain::Abstract>
Recti::Domain::Factory::
build() const
{
  std::string domainType = pList_.get<std::string>("Type");
  if ( domainType.compare("Circle")==0 )
      return buildCircle();
  else if ( domainType.compare("Ellipse")==0 )
      return buildEllipse();
  else if ( domainType.compare("Polygon")==0 )
      return buildPolygon();
  else if ( domainType.compare("Rectangle")==0 )
      return buildRectangle();
  else if ( domainType.compare("Square")==0 )
      return buildSquare();
  else
  {
      TEST_FOR_EXCEPTION( true, std::logic_error,
                          "Unknown domain type \"" << domainType << "\"." );
  }
}
예제 #2
0
int main(void){
    int squareSize;
    int** square;
    
    //Grabbing initial input
    printf("This program creates a magic square if a specified size.\nThe size must be an odd number between 1 and 99.\n");
    printf("Enter size of magic square: ");
    scanf("%i", &squareSize);
    
    // Some basic error checking
    while(!isOdd(squareSize)){
        printf("The size must be an odd number between 1 and 99.\n");
        printf("Enter size of magic square: ");
        scanf("%i", &squareSize);
    }
    
    //Building and printing square
    square = buildSquare(squareSize);
    printSquare(square, squareSize);
    free(square);
    
    return 0;
}
예제 #3
0
/*!
onInit initializes the global variables and builds the shader program. It
should be called after a window with a valid OpenGL context is present.
*/
void onInit()
{  
    // Set light parameters
    _globalAmbi.set(0.0f, 0.0f, 0.0f);
    _lightPos.set( 0.0f, 0.0f, 100.0f);
    _lightDir.set( 0.0f, 0.0f,-1.0f);
    _lightAmbient.set( 0.1f, 0.1f, 0.1f);
    _lightDiffuse.set( 1.0f, 1.0f, 1.0f);
    _lightSpecular.set( 1.0f, 1.0f, 1.0f);
    _matAmbient.set( 1.0f, 1.0f, 1.0f);
    _matDiffuse.set( 1.0f, 1.0f, 1.0f);
    _matSpecular.set( 1.0f, 1.0f, 1.0f);
    _matEmissive.set( 0.0f, 0.0f, 0.0f);
    _matShininess = 100.0f;

    // backwards movement of the camera
    _camZ = -3.0f;

    // Mouse rotation parameters
    _rotX = 0;
    _rotY = 0;
    _deltaX = 0;
    _deltaY = 0;
    _mouseLeftDown = false;

    // Load textures
    _textureID = glUtils::buildTexture("../_data/images/textures/earth2048_C.jpg");

    // Load, compile & link shaders
    _shaderVertID = glUtils::buildShader("../_data/shaders/ADSTex.vert", GL_VERTEX_SHADER);
    _shaderFragID = glUtils::buildShader("../_data/shaders/ADSTex.frag", GL_FRAGMENT_SHADER);
    _shaderProgID = glUtils::buildProgram(_shaderVertID, _shaderFragID);

    // Activate the shader program
    glUseProgram(_shaderProgID);

    // Get the variable locations (identifiers) within the vertex & pixel shader programs
    _pLoc            = glGetAttribLocation (_shaderProgID, "a_position");
    _nLoc            = glGetAttribLocation (_shaderProgID, "a_normal");
    _tLoc            = glGetAttribLocation (_shaderProgID, "a_texCoord");
    _mvMatrixLoc     = glGetUniformLocation(_shaderProgID, "u_mvMatrix");
    _mvpMatrixLoc    = glGetUniformLocation(_shaderProgID, "u_mvpMatrix");
    _nMatrixLoc      = glGetUniformLocation(_shaderProgID, "u_nMatrix");
    _globalAmbiLoc   = glGetUniformLocation(_shaderProgID, "u_globalAmbi");
    _lightPosVSLoc   = glGetUniformLocation(_shaderProgID, "u_lightPosVS");
    _lightDirVSLoc   = glGetUniformLocation(_shaderProgID, "u_lightDirVS");
    _lightAmbientLoc = glGetUniformLocation(_shaderProgID, "u_lightAmbient");
    _lightDiffuseLoc = glGetUniformLocation(_shaderProgID, "u_lightDiffuse");
    _lightSpecularLoc= glGetUniformLocation(_shaderProgID, "u_lightSpecular");
    _matAmbientLoc   = glGetUniformLocation(_shaderProgID, "u_matAmbient");
    _matDiffuseLoc   = glGetUniformLocation(_shaderProgID, "u_matDiffuse");
    _matSpecularLoc  = glGetUniformLocation(_shaderProgID, "u_matSpecular");
    _matEmissiveLoc  = glGetUniformLocation(_shaderProgID, "u_matEmissive");
    _matShininessLoc = glGetUniformLocation(_shaderProgID, "u_matShininess");
    _texture0Loc     = glGetUniformLocation(_shaderProgID, "u_texture0");

    // Build object
    buildSquare();

    // Set some OpenGL states
    glClearColor(0.0f, 0.0f, 0.0f, 1);  // Set the background color
    glEnable(GL_DEPTH_TEST);            // Enables depth test
    glEnable(GL_CULL_FACE);             // Enables the culling of back faces
    GETGLERROR;                         // Check for OpenGL errors
}