LoadingScreen::LoadingScreen() : GL2DVertexGroup(GL_TRIANGLE_STRIP,4) {
	//Draw the classic square
	vat(0) = vec2(0,0);
	xat(0) = vec2(0,0);
	vat(1) = vec2(0,200);
	xat(1) = vec2(0,1);
	vat(2) = vec2(200,0);
	xat(2) = vec2(1,0);
	vat(3) = vec2(200,200);	
	xat(3) = vec2(1,1);

	//Load the texture
	unsigned int textureWidth, textureHeight;
	vector<unsigned char> image;
	unsigned error = lodepng::decode(image,textureWidth,textureHeight,"loading.png");
    if(error)
    {
        SDL_Log("Lodepng error (%u) - %s", error, lodepng_error_text(error));
		return;
    }
    
	//I should have moved the png->texture into a utility library
	//later...
	glGenTextures( 1, &textureId );
	glBindTexture(GL_TEXTURE_2D, textureId);


	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, textureWidth,
				textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
				&image[0] );

	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	

}
void MaterialSelectionControl::Draw(GL2DProgram * shaders) {
	shaders->Model.Apply();
	//Draw the classic square
	vat(0) = vec2(0,0);
	xat(0) = vec2(0,0);
	vat(1) = vec2(0,calculatedPosition.Height);
	xat(1) = vec2(0,1);
	vat(2) = vec2(calculatedPosition.Width,0);
	xat(2) = vec2(1,0);
	vat(3) = vec2(calculatedPosition.Width,calculatedPosition.Height);	
	xat(3) = vec2(1,1);
	//Enable the texture
	CurrentSystem->Textures.GetTexture("terrain/tiles-lowres.png")->Bind();
	shaders->SetColor(vec4(1,1,1,1));
	shaders->EnableTexture(true);

	//Draw the square
	GL2DVertexGroup::Draw(shaders);

	//Draw the selection shape here instead of as a child
	if (currentlySelectedMaterial >= 0) {
		Rect pos = Rect((currentlySelectedMaterial % 4)*1.0f/4.0f*position.Width,
			(int)(currentlySelectedMaterial / 4)*1.0f/4.0f*position.Height
			,position.Width/4.0f-20,position.Height/4.0f-20);

		shaders->Model.PushMatrix();
		shaders->Model.Translate(pos.X+10,pos.Y+10,0);
		shaders->Model.Apply();
		selectionShape.color = vec4(1,1,1,.5);
		selectionShape.OverrideCalculatedSize(pos);
		selectionShape.Draw(shaders);
		shaders->Model.PopMatrix();
	}
}
Exemple #3
0
void f(int *p) {
  int a[2], b[3], c[4];

  cat0(0);

  cat(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
  cat(a); // expected-warning {{array argument is too small; contains 2 elements, callee requires at least 3}}
  cat(b);
  cat(c);
  cat(p);

  vat(1, 0); // expected-warning {{null passed to a callee that requires a non-null argument}}
  vat(3, b);
}
//Attempt to load a ninepatch from file
NinePatchBinary::NinePatchBinary(string filename) {
	vector<unsigned char> ninepatchData;
	lodepng::load_file(ninepatchData,filename);
	valid = false;
	//Check that the file opened
	if (ninepatchData.size() < sizeof(savedNinepatch)) {
		cout << "Failed to open 9patch: " << filename << "\n";
		return;
	}
	//Read in bytes until the struct is populated
	memcpy((char *)&savedNinepatch,ninepatchData.data(),sizeof(savedNinepatch));
	//Check file signature
	if (string(savedNinepatch.fileSignature,4) != "PTCH") {
		cout << "Corrupted 9patch: " << filename << "\n";
		return;
	}
	//Check if the endian-ness of this machine is different than the file save type
	if (savedNinepatch.endianByte != 1) {
		//Swap required
		SwapEndian(&savedNinepatch.height);
		SwapEndian(&savedNinepatch.left);
		SwapEndian(&savedNinepatch.top);
		SwapEndian(&savedNinepatch.width);
	}
	//else all done loading binary file. Now load the texture into opengl
	
	//Derive texture name from ninepatch file name
	if (filename.size() <= 6) {
		cout << "Invalid 9patch filename: " << filename << "\n";
		return;
	}

	string imageFilename = filename.substr(0,filename.size()-6) + ".cropped.png";
	unsigned int width;
	unsigned int height;
	vector<unsigned char> image;
	//Read the file
	unsigned int error = lodepng::decode(image,width,height,imageFilename);
	if (error) {
		cout << "Failed to load texture for 9patch: " << filename << "\n";
		return;
	}

	glGenTextures( 1, (GLuint*)&openglTextureId );
	glBindTexture(GL_TEXTURE_2D, openglTextureId);


	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width,
				height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
				&image[0] );

	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );	//GL_NEAREST FOR SPEED
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	//GL_NEAREST FOR SPEED
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	//record image size
	imageSize = vec2(width,height);

	{
		//Build the texture coordinates
		//This part copied and modified from the control.cpp file
		//that's what I use "vat" instead of modifying coordiantes directly
		vector<vec2> vat(22);

		float top = (float)savedNinepatch.top/imageSize.y;
		float left = (float)savedNinepatch.left/imageSize.x;
		float width = (float)savedNinepatch.width/imageSize.x;
		float height = (float)savedNinepatch.height/imageSize.y;

		//Draw the textured nine patch
		//by resizing the texture coordinates
		//using the 9patch system
		//Coordinates arranged like this:
		//A = 0, B = 1, C = 2, etc.
		//A  C  E  G  
		//BN DL FJ H 
		//O  MQ KS IU
		//P  R  T  V
		vat[0] = vec2(0,0);
		vat[1] = vec2(0,top);
		vat[2] = vec2(left,0);
		vat[3] = vec2(left,top);
		vat[4] = vec2(left+width,0);
		vat[5] = vec2(left+width,top);
		vat[6] = vec2(1,0);
		vat[7] = vec2(1,top);
		vat[8] = vec2(1,top+height);
		vat[9] = vat[5];
		vat[10] = vec2(left+width,top+height);
		vat[11] = vat[3];
		vat[12] = vec2(left,top+height);
		vat[13] = vat[1];
		vat[14] = vec2(0,top+height);
		vat[15] = vec2(0,1);
		vat[16] = vat[12];
		vat[17] = vec2(left,1);
		vat[18] = vat[10];
		vat[19] = vec2(left+width,1);
		vat[20] = vat[8];
		vat[21] = vec2(1,1);

		coordinates = vat;
	}


	valid = true;
	cout << "Successfully loaded 9patch: " << filename << "\n";
}
Exemple #5
0
int main(void) 
{
  va_list t;
  vat (t, 1);
  exit (0);
}