Пример #1
0
void Cube::reset(bool bufferReady) {
	cSides[0] = cubeNS::DEF_COLORS[0];
	cSides[1] = cubeNS::DEF_COLORS[1];
	cSides[2] = cubeNS::DEF_COLORS[2];
	cSides[3] = cubeNS::DEF_COLORS[3];
	cSides[4] = cubeNS::DEF_COLORS[4];
	cSides[5] = cubeNS::DEF_COLORS[5];

	rotation[0] = 0.0f;
	rotation[1] = 0.0f;
	rotation[2] = 0.0f;

	scale[0] = 1.0f;
	scale[1] = 1.0f;
	scale[2] = 1.0f;

	translate[0] = 0.0f;
	translate[1] = 0.0f;
	translate[2] = 0.0f;

	if (bufferReady) {
		genCube();
		glBufferSubData(GL_ARRAY_BUFFER, cubeNS::TOTAL * sizeof(glm::vec4), cubeNS::TOTAL * sizeof(glm::vec3), colors);
	}
}
Пример #2
0
Cube::Cube(float sx, float sy, float sz, int nx, int ny, int nz, bool smoothNormals) {	
	//Log::msg("Cube::Cube sx:%f sy:%f sz:%f nx:%d ny:%d nz:%d", sx, sy, sz, nx, ny, nz);
	vertexStream.addAttrib("position", TYPE_VEC3);
	vertexStream.addAttrib("normal", TYPE_VEC3);
	vertexStream.addAttrib("texCoord0", TYPE_VEC2);
	
	genCube(sx, sy, sz, nx, ny, nz, smoothNormals);
}	
Пример #3
0
DrawDebug::DrawDebug() {
#if DEBUG
    auto vecShader  = loadProgram("Shaders/_debug/vecvertexShader.glsl", "Shaders/_debug/vecfragmentShader.glsl");
    auto meshShader = loadProgram("Shaders/_debug/meshvertexShader.glsl", "Shaders/_debug/meshfragmentShader.glsl");
    
    arrow = loadOBJ("Assets/_debug/arrow.obj");
    if (!arrow) {
        genCone("Assets/_debug/arrow.obj", 8);
        arrow = loadOBJ("Assets/_debug/arrow.obj");
    }
    
    sphere = loadOBJ("Assets/_debug/sphere.obj");
    if (!sphere) {
        genSphere("Assets/_debug/sphere.obj", 8);
        sphere = loadOBJ("Assets/_debug/sphere.obj");
    }

    box = loadOBJ("Assets/_debug/cube.obj");
    if (!box) {
        genCube("Assets/_debug/cube.obj");
        box = loadOBJ("Assets/_debug/cube.obj");
    }

    GLattrarr attrSetup;
    const auto vecSize = sizeof(GLfloat) * FLOATS_PER_VERT;

    vecVAO.create();
    vecVAO.bind();
    vecBuffer.create(GL_ARRAY_BUFFER, GL_STREAM_DRAW);

    vecBuffer.bind();
    vecBuffer.data(vecSize * MAX_VECTORS * 4, nullptr);
    debugVectors.reserve(MAX_VECTORS * 4);

    attrSetup.add<vec3>(2);
    attrSetup.apply();

    const auto mSetup = [](GLattrarr& attrSetup) {
        attrSetup.add<vec4>(1, 1);
        attrSetup.add<mat4>(1, 1);
    };

    arrows = InstMesh<m_MeshData>(arrow.get(), MAX_VECTORS, 1, mSetup);
    spheres = InstMesh<m_MeshData>(sphere.get(), MAX_SPHERES, 1, mSetup);
    boxes = InstMesh<m_MeshData>(box.get(), MAX_BOXES, 1, mSetup);

    vecVAO.unbind();

    vecCam  = vecShader.getUniform<mat4>("cameraMatrix");
    meshCam = meshShader.getUniform<mat4>("cameraMatrix");

    vecMat.setShaders(vecShader);
    vecMat.setTextures();

    meshMat.setShaders(meshShader);
    meshMat.setTextures();
#endif
}
Пример #4
0
void Cube::applyColor(Side side, Colors color) {
	if (side != ALL) {
		cSides[side] = color;
	} else {
		cSides[0] = color;
		cSides[1] = color;
		cSides[2] = color;
		cSides[3] = color;
		cSides[4] = color;
		cSides[5] = color;
	}

//Update the buffer
	genCube();
	glBufferSubData(GL_ARRAY_BUFFER, cubeNS::TOTAL * sizeof(glm::vec4), cubeNS::TOTAL * sizeof(glm::vec3), colors);
}
Пример #5
0
bool Cubes::Init() 
{
	scene = new Scene();


	scene->ambient = 0x000000;

	int index = 0;
	for (int z = 0; z < CUBES_RESZ; z++)
	{
		for (int y = 0; y < CUBES_RESY; y++)
		{
			for (int x = 0; x < CUBES_RESX; x++)
			{
				scene->addObject(genCube(1, 0.5f, "env03"));

				scene->object[index]->setLoc(-((CUBES_RESX / 2) * 0.5f) + (x * 0.5f), 
					                         -((CUBES_RESY / 2) * 0.5f) + (y * 0.5f), 
											 -((CUBES_RESZ / 2) * 0.5f) + (z * 0.5f));

				scene->object[index]->transMode = UNI_ADD;

				scene->object[index]->setDiffuse(0.2f, 0.2f, 0.2f);

				scene->object[index]->finish(false);

				index++;
			}
		}
	}

	scene->addLight(new Light(1, 1, 1, 1));


	scene->camera->aspect = 0.65f;



	return true;
}   
Пример #6
0
void Cube::buildBuffer() {
//Generate the cube coordinate points and colors
	genCube();

//Create the buffer
	glGenBuffers(1, &buffer);

//Bind the buffers to their respective data values
	glBindBuffer(GL_ARRAY_BUFFER, buffer);
	glBufferData(GL_ARRAY_BUFFER, cubeNS::TOTAL * (sizeof(glm::vec4) + sizeof(glm::vec3)), NULL, GL_STATIC_DRAW);
	glBufferSubData(GL_ARRAY_BUFFER, 0, cubeNS::TOTAL * sizeof(glm::vec4), points);
	glBufferSubData(GL_ARRAY_BUFFER, cubeNS::TOTAL * sizeof(glm::vec4), cubeNS::TOTAL * sizeof(glm::vec3), colors);

//Extract the position from the shader
	GLuint vPosition = glGetAttribLocation(shaderProgram, cubeNS::SHD_LOCATION);
	glEnableVertexAttribArray(vPosition);
	glVertexAttribPointer(vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));

//Extract the color from the shader
	GLuint vColor = glGetAttribLocation(shaderProgram, cubeNS::SHD_COLOR);
	glEnableVertexAttribArray(vColor);
	glVertexAttribPointer(vColor, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(points)));
}
Пример #7
0
static void
init(int argc, char *argv[])
{
  static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0};
  static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0};
  static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0};
  static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0};
  GLint i;

  glLightfv(GL_LIGHT0, GL_POSITION, pos);
#if 0
  glEnable(GL_CULL_FACE);
#endif
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_DEPTH_TEST);

  /* make the gears */
  Gear1 = glGenLists(1);
  glNewList(Gear1, GL_COMPILE);
  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
  gear(1.0, 4.0, 1.0, 20, 0.7);
  glEndList();

  Gear2 = glGenLists(1);
  glNewList(Gear2, GL_COMPILE);
  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
  gear(0.5, 2.0, 2.0, 10, 0.7);
  glEndList();

  Gear3 = glGenLists(1);
  glNewList(Gear3, GL_COMPILE);
  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
  gear(1.3, 2.0, 0.5, 10, 0.7);
  glEndList();

  cubeList = glGenLists(1);
  glNewList(cubeList, GL_COMPILE);
  genCube();
  glEndList();

  glEnable(GL_NORMALIZE);

  /* xxx make size dynamic */
  TexWidth = 256;
  TexHeight = 256;

   glBindTexture(GL_TEXTURE_2D, TexObj);
   glTexImage2D(GL_TEXTURE_2D, 0, IntFormat, TexWidth, TexHeight, 0,
                GL_RGBA, GL_UNSIGNED_BYTE, NULL);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

   glGenFramebuffersEXT(1, &GearsFbo);
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, GearsFbo);
   glGenRenderbuffersEXT(1, &GearsDepthRB);
   glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, GearsDepthRB);
   glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, TexWidth, TexHeight);
   glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, GearsDepthRB);
   glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, TexObj, 0);

   GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
   
   if(status != GL_FRAMEBUFFER_COMPLETE_EXT) {
     printf("!!! FB not complete\n");
     exit(1);
   }

   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

  for ( i=1; i<argc; i++ ) {
    if (strcmp(argv[i], "-info")==0) {
      printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
      printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
      printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
      printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
    }
  }
}
Пример #8
0
void Mesh::genCube(glm::vec3 dimensions) {
	genCube(dimensions, glm::vec3(dimensions.x/2, dimensions.y/2, dimensions.z/2));
}