コード例 #1
0
int GFXCore::Sprites::loadSprite(IDirect3DDevice9* device, const wchar_t* fileName, Textures& textures, const D3DXVECTOR3& initPos, const bool centerIsTopLeft /*= true*/, const D3DCOLOR initColor /*= D3DCOLOR_RGBA(255, 255, 0, 255)*/, RECT* clipRect /*= NULL*/)
{
	for (unsigned int i = 0; i < spriteList.size(); ++i)
		if (0 == wcscmp(fileName, spriteList[i].strFileName))
			return i;

	SpriteData newSprite;
	memset(&newSprite, NULL, sizeof(SpriteData));
	wcscpy_s(newSprite.strFileName, MAX_FILE_NAME, fileName);

	newSprite.nTextureId = textures.loadTexture(device, fileName);
	if (-1 == newSprite.nTextureId)
		return -1;
	
	newSprite.position = initPos;
	newSprite.color = initColor;

	if (centerIsTopLeft) {
		newSprite.bCenterIsTopLeft = true;
	} else {
		newSprite.center.x = (float)textures.getTextureWidth(newSprite.nTextureId) * 0.5f;
		newSprite.center.y = (float)textures.getTextureHeight(newSprite.nTextureId) * 0.5f;
	}

	if (clipRect) {
		newSprite.clipRect = *clipRect;
		newSprite.bHasClipRect = true;
	}

	spriteList.push_back(newSprite);

	return ++nIdGenerator;
}
コード例 #2
0
void GFXCore::Sprites::render(const int id, Textures& textures)
{
#if defined (_DEBUG) | defined(DEBUG)
	CHECK_OUT_OF_BOUNDS(id, (int)spriteList.size());
#endif

	HRESULT hr = pSprite->Draw(textures.getTexture(spriteList[id].nTextureId),
											spriteList[id].bHasClipRect == true ? &spriteList[id].clipRect : NULL,
											spriteList[id].bCenterIsTopLeft == true ? NULL : &spriteList[id].center,
											&spriteList[id].position,
											spriteList[id].color);

	if (FAILED(hr))
		ErrorMsg(L"Sprite Draw Failure!", L"Sprites::render()");
}
コード例 #3
0
ファイル: Objects.cpp プロジェクト: N0Paranoia/SwissShark
void Objects::RenderBackground(SDL_Renderer* Renderer, SDL_Rect* camera, bool doorStatus, bool diverStatus, bool sawStatus, bool swordStatus)
{
	if(diverStatus)
	{
		frameCounter += frameSpeed;
		if(frameCounter > frameSwitch)
		{
			if(!killedDiver)
			{
				frameHose ++;
				frameDiver ++;
				frameCounterHose = 0;
				frameCounterDiver = 0;
				if(frameHose == endFrameHose)
				{
					killedDiver = true;
				}
			}
		}
	}
	ItemSheetTexture.Render(Renderer, this->diverHose.x - camera->x, this->diverHose.y - camera->y, &ObjectClips[frameHose]);
	ItemSheetTexture.Render(Renderer, this->diver.x - camera->x, this->diver.y - camera->y, &ObjectClips[frameDiver]);
	ItemSheetTexture.Render(Renderer, this->boat.x - camera->x, this->boat.y - camera->y, &ObjectClips[frameBoat]);
}
コード例 #4
0
ファイル: Objects.cpp プロジェクト: N0Paranoia/SwissShark
void Objects::RenderForeground(SDL_Renderer* Renderer, SDL_Rect* camera, bool doorStatus, bool diverStatus, bool sawStatus, bool swordStatus)
{
	if(!doorStatus)
	{
		ItemSheetTexture.Render(Renderer, this->door.x - camera->x, this->door.y - camera->y, &ObjectClips[OBJ_DOOR]);
	}
	else
	{
		ItemSheetTexture.Render(Renderer, this->door.x - camera->x, this->door.y - camera->y, &ObjectClips[OBJ_DOOR_OPEN]);
	}
	if(!sawStatus)
	{
		ItemSheetTexture.Render(Renderer, this->item_saw.x - camera->x, this->item_saw.y - camera->y, &ObjectClips[OBJ_SAW]);
	}
	if(!swordStatus)
	{
		ItemSheetTexture.Render(Renderer, this->item_sword.x - camera->x, this->item_sword.y - camera->y, &ObjectClips[OBJ_SWORD]);
	}
	ItemSheetTexture.Render(Renderer, this->plantSprite1.x - camera->x, this->plantSprite1.y - camera->y, &ObjectClips[OBJ_PLANT]);
	ItemSheetTexture.Render(Renderer, this->plantSprite2.x - camera->x, this->plantSprite2.y - camera->y, &ObjectClips[OBJ_PLANT]);
	ItemSheetTexture.Render(Renderer, this->fisherman.x - camera->x, this->fisherman.y - camera->y, &ObjectClips[OBJ_FISHINGROD]);
}
コード例 #5
0
ファイル: image.cpp プロジェクト: david-guerrero/MITK
void iil4mitkImage::drawTextures (iil4mitkWidget* widget)
{
  const unsigned int s = _size; // size of the tiles
  unsigned int n, m;  // number of the tiles

  n = (unsigned int) ceilf ((float) _rw / (float) (s - 2));
  m = (unsigned int) ceilf ((float) _rh / (float) (s - 2));

  /* Allocate memory for the textures */
  
  Textures* textures;
  {
    iil4mitkWidget* w;
    unsigned int available, total;
  
    //w = (widget->IsSharing () ? widget->SharedWidget () : widget);
    w = (false ? NULL : widget);
    std::map<void*,Textures*>::iterator tex_it = _textures.find (w);
    if(tex_it!=_textures.end())
      textures = tex_it->second;
    else
      textures = NULL;

    if (!textures) {
      textures = new Textures ();
      typedef std::pair <void*, std::vector<_iil4mitkTexture*>* > TexturePair;
      _textures.insert (TexturePair(w, textures));
    }
    available = textures->size (); 
    total = n * m;
    //textures->resize (total);
    int iii;
    for (unsigned int i = available; i < total; i++)
    {
      textures->push_back(new _iil4mitkTexture (w));
      iii=textures->size ();
    }
    widget->MakeCurrent ();
  }  

  /* Render the textures */

  glScalef ((float) (s-2), (float) (s-2), 1.0);
  for (unsigned int i = 0; i < n; i++)
  {
    unsigned int pos [2]; // left-top corner of the region
    unsigned int len [2]; // extent of the region
    unsigned int tex [2]; // size of the texture
    float res [2];        // resolution of the texture
    
    pos [0] = _rx+i*(s-2);
          len [0] = (pos[0]+(s-2)>_rw ? _rw-pos[0] : s-2);  
    tex [0] = power2(s);
    res [0] = 1.0f/tex[0];
    for (unsigned int j = 0; j < m; j++) 
    {
      _iil4mitkTexture* texture;
      
      texture = (*textures)[i*m+j];
      pos [1] = _ry+j*(s-2);
      len [1] = (pos[1]+(s-2)>_rh ? _rh-pos[1] : s-2);
      tex [1] = power2(s);
      res [1] = 1.0f/tex[1];
  
      //if (widget->isVisible (pos [0], pos [1], len [0], len [1])) {
      if (true) {
      // widget->makeCurrent ();  
      texture->bind ();
      // widget->makeCurrent ();  
      texture->setSize (tex[0], tex[1]);
      texture->setModel (_model);
      texture->setInterpolation (_interpolation);
      if (!texture->isValid ()) 
      {
        updateTexture (texture, pos[0], pos[1], len[0], len[1]);
      }  

      glBegin (GL_QUADS);
      glTexCoord2f (res[0], res[1]); glVertex3f (0.0, 0.0, 0.0);
      glTexCoord2f (1.0-res[0], res[1]); glVertex3f (1.0, 0.0, 0.0);
      glTexCoord2f (1.0-res[0], 1.0-res[1]); glVertex3f (1.0, 1.0, 0.0);
      glTexCoord2f (res[0], 1.0-res[1]); glVertex3f (0.0, 1.0, 0.0);
      glEnd ();
      }
      glTranslatef (0.0, 1.0, 0.0);
    }
    glTranslatef (1.0, -((float) m), 0.0);
  }
}
コード例 #6
0
ファイル: Objects.cpp プロジェクト: N0Paranoia/SwissShark
int Objects::LoadMedia(SDL_Renderer* Renderer)
{
	//Load Item sheet
	if((ItemSheetTexture.LoadFromFile(Renderer, "assets/objectSheet.png")) == NULL)
	{
		cout << "Unable to load Item Texture! SDL_Error: " << SDL_GetError() << endl;
		return false;
	}
	else
	{
		ObjectClips[0].x = 0;
		ObjectClips[0].y = 0;
		ObjectClips[0].w = TILE_SIZE;
		ObjectClips[0].h = TILE_SIZE;
		
		ObjectClips[1].x = 0;
		ObjectClips[1].y = TILE_SIZE;
		ObjectClips[1].w = TILE_SIZE;
		ObjectClips[1].h = TILE_SIZE;
		// Hose sprite
		ObjectClips[2].x = 7*TILE_SIZE;
		ObjectClips[2].y = 0;
		ObjectClips[2].w = TILE_SIZE;
		ObjectClips[2].h = 8*TILE_SIZE;
		
		ObjectClips[3].x = 8*TILE_SIZE;
		ObjectClips[3].y = 0;
		ObjectClips[3].w = TILE_SIZE;
		ObjectClips[3].h = 8*TILE_SIZE;
		
		ObjectClips[4].x = 9*TILE_SIZE;
		ObjectClips[4].y = 0;
		ObjectClips[4].w = TILE_SIZE;
		ObjectClips[4].h = 8*TILE_SIZE;
		
		ObjectClips[5].x = 10*TILE_SIZE;
		ObjectClips[5].y = 0;
		ObjectClips[5].w = TILE_SIZE;
		ObjectClips[5].h = 8*TILE_SIZE;
		// Diver sprite 
		ObjectClips[6].x = 1*TILE_SIZE;
		ObjectClips[6].y = 9*TILE_SIZE;
		ObjectClips[6].w = 2*TILE_SIZE;
		ObjectClips[6].h = 4*TILE_SIZE;
		
		ObjectClips[7].x = 3*TILE_SIZE;
		ObjectClips[7].y = 9*TILE_SIZE;
		ObjectClips[7].w = 2*TILE_SIZE;
		ObjectClips[7].h = 4*TILE_SIZE;
		
		ObjectClips[8].x = 5*TILE_SIZE;
		ObjectClips[8].y = 9*TILE_SIZE;
		ObjectClips[8].w = 2*TILE_SIZE;
		ObjectClips[8].h = 4*TILE_SIZE;
		
		ObjectClips[9].x = 7*TILE_SIZE;
		ObjectClips[9].y = 9*TILE_SIZE;
		ObjectClips[9].w = 2*TILE_SIZE;
		ObjectClips[9].h = 4*TILE_SIZE;
		//Door sprite	
		ObjectClips[10].x = 0*TILE_SIZE;
		ObjectClips[10].y = 2*TILE_SIZE;
		ObjectClips[10].w = TILE_SIZE;
		ObjectClips[10].h = 2*TILE_SIZE;
		
		ObjectClips[11].x = 1*TILE_SIZE;
		ObjectClips[11].y = 2*TILE_SIZE;
		ObjectClips[11].w = TILE_SIZE;
		ObjectClips[11].h = 2*TILE_SIZE;
		//plant sprite				
		ObjectClips[12].x = 3*TILE_SIZE;
		ObjectClips[12].y = 4*TILE_SIZE;
		ObjectClips[12].w = 2*TILE_SIZE;
		ObjectClips[12].h = 2*TILE_SIZE;
		//fishing rod sprite
		ObjectClips[13].x = 0*TILE_SIZE; 
		ObjectClips[13].y = 4*TILE_SIZE;
		ObjectClips[13].w = 1*TILE_SIZE;
		ObjectClips[13].h = 12*TILE_SIZE;
		//fishing boat sprite
		ObjectClips[14].x = 1*TILE_SIZE; 
		ObjectClips[14].y = 13*TILE_SIZE;
		ObjectClips[14].w = 10*TILE_SIZE;
		ObjectClips[14].h = 3*TILE_SIZE;
	}	
	return true;
}
コード例 #7
0
ファイル: Objects.cpp プロジェクト: N0Paranoia/SwissShark
void Objects::Cleanup()
{
	ItemSheetTexture.Free();
}
コード例 #8
0
ファイル: main.cpp プロジェクト: SalamiCo/IGrP7
void initGL() {	 	
	buildScene();

	glClearColor(0.0f,0.0f,0.0f,1.0);
    glEnable(GL_LIGHTING);
	globalOn = true;

	glEnable(GL_COLOR_MATERIAL);
	glMaterialf(GL_FRONT, GL_SHININESS, 0.1f);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_NORMALIZE);
	glShadeModel(GL_SMOOTH);

	// Viewport set up
    glViewport(0, 0, WIDTH, HEIGHT);  

	 // Light0
    glEnable(GL_LIGHT0);
    GLfloat d[]={1.0,1.0,1.0,1.0};
    glLightfv(GL_LIGHT0, GL_DIFFUSE, d);
    GLfloat a[]={0.3f,0.3f,0.3f,1.0};
    glLightfv(GL_LIGHT0, GL_AMBIENT, a);
	GLfloat p[]={25.0, 25.0, 0.0, 1.0};	 
	glLightfv(GL_LIGHT0, GL_POSITION, p);

	//Light2
	glEnable(GL_LIGHT2);
	GLfloat p2[]={1.0, 1.0, 0.0, 0.0};
	glLightfv(GL_LIGHT2, GL_POSITION, p2);
	GLfloat d2[]={1.0,1.0,1.0,1.0};
    glLightfv(GL_LIGHT2, GL_DIFFUSE, d2);
    GLfloat a2[]={0.3f,0.3f,0.3f,1.0};
    glLightfv(GL_LIGHT2, GL_AMBIENT, a2);

	//Niebla
	glEnable(GL_FOG);
	glFogi(GL_FOG_MODE, GL_LINEAR);
	GLfloat color[]={0.0f,0.0f,1.0f,0.0f};
	//glFogfv(GL_FOG_COLOR, color);
	//glFogf(GL_FOG_DENSITY, 0.5f);
	glFogi(GL_FOG_START, 20);
	glFogi(GL_FOG_END, 50);

	//Texturas
	unsigned int width;
	unsigned int height;
	unsigned char * data = loadBMPRaw("./bmp/madera.bmp", width, height);
	unsigned char * data2 = loadBMPRaw("./bmp/grass.bmp", width, height);
	cout<< width << endl;
	cout<< height << endl;

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, 0);


	//Textura mesa
	glBindTexture(GL_TEXTURE_2D, t.getTexture(0));
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

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

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);

	//Textura tapete
	glBindTexture(GL_TEXTURE_2D, t.getTexture(1));
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data2);

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

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
 }
コード例 #9
0
ファイル: main.cpp プロジェクト: moccajoghurt/raycasting_ls
void cast_rays(Player& p, Map& m, Textures& t, SDL_Renderer* renderer) {
	
	double current_angle = p.angle - Player::field_of_view/2;
	current_angle = current_angle < 0 ? current_angle + 360 : current_angle;
	
	Uint32 floor_pixels[Data::render_size_x * Data::render_size_y];
	memset(floor_pixels, 0, Data::render_size_x * Data::render_size_y * sizeof(Uint32));
	vector<sprite_drawdata_t> sprites;
	for (int x = 0; x < Player::plane_x; x++) {
		
		
		//find first horizontal grid
		double first_grid_horizontal_x;
		double first_grid_horizontal_y;
		if (current_angle > 180) {
			first_grid_horizontal_y = ((int)p.pos_y / Field::width) * Field::width + Field::width;
		} else {
			first_grid_horizontal_y = ((int)p.pos_y / Field::width) * Field::width - 1;
		}
		
		first_grid_horizontal_x = p.pos_x + (p.pos_y - first_grid_horizontal_y) / Data::get_tan_val( 180 - current_angle);
		
		
		//calculate horizontal stepsize
		double grid_stepsize_horizontal_x;
		double grid_stepsize_horizontal_y;
		if (current_angle > 180) {
			grid_stepsize_horizontal_y = Field::width;
			grid_stepsize_horizontal_x = Field::width / Data::get_tan_val(current_angle - 180);
		} else {
			grid_stepsize_horizontal_y = -Field::width;
			grid_stepsize_horizontal_x = Field::width / Data::get_tan_val(180 - current_angle);
		}
		
		//grid_stepsize_horizontal_x = current_angle < 90 ? -grid_stepsize_horizontal_x : grid_stepsize_horizontal_x;
		
		//find first vertical grid
		double first_grid_vertical_x;
		double first_grid_vertical_y;
		if (current_angle < 90 || current_angle > 270) {
			first_grid_vertical_x = ((int)p.pos_x / Field::width) * Field::width - 1;
			first_grid_vertical_y = p.pos_y + (p.pos_x - first_grid_vertical_x) * Data::get_tan_val(180 - current_angle);
		} else {
			first_grid_vertical_x = ((int)p.pos_x / Field::width) * Field::width + Field::width;
			first_grid_vertical_y = p.pos_y + (p.pos_x - first_grid_vertical_x) * Data::get_tan_val(180 - current_angle);
		}
		
		
		//calculate vertical stepsize
		double grid_stepsize_vertical_x;
		double grid_stepsize_vertical_y;
		if (current_angle < 90 || current_angle > 270) {
			grid_stepsize_vertical_x = -Field::width;
			grid_stepsize_vertical_y = -Field::width * Data::get_tan_val(current_angle - 180);
		} else {
			grid_stepsize_vertical_x = Field::width;
			grid_stepsize_vertical_y = Field::width * Data::get_tan_val(current_angle - 180);
		}

		
		/*
		//DEBUGGING
		if (x == Debugger::current_x_pane_debug) {
			cout << "angle: " << current_angle << endl;
			cout << "horizontal x: " << grid_stepsize_horizontal_x << "\thorizontal y: " << grid_stepsize_horizontal_y << endl;
		}
		if (x == Debugger::current_x_pane_debug) {
			cout << "vertical x: " << grid_stepsize_vertical_x << "\tvertical y: " << grid_stepsize_vertical_y << endl;
			cout << "##" << endl;
		}
		*/
		
		
		//calculate grid steps
		double current_grid_horizontal_x = first_grid_horizontal_x;
		double current_grid_horizontal_y = first_grid_horizontal_y;
		double current_grid_vertical_x = first_grid_vertical_x;
		double current_grid_vertical_y = first_grid_vertical_y;
		int intersection_count = 0;
		double last_horizontal_distance = 0;
		double last_vertical_distance = 0;
		
		for (int i = 0; i < Player::view_depth; i++) {
			
			if (current_grid_horizontal_x >= 0 && current_grid_horizontal_x / Field::width < m.field_num_x && current_grid_horizontal_y >= 0 && current_grid_horizontal_y / Field::height < m.field_num_y && last_horizontal_distance < Player::view_distance) {
				
				SDL_Rect field_pos;
				field_pos.x = current_grid_horizontal_x / Field::width;
				field_pos.y = current_grid_horizontal_y / Field::width;
				
				
				double distance = sqrt( (p.pos_x - current_grid_horizontal_x)*(p.pos_x - current_grid_horizontal_x) + (p.pos_y - current_grid_horizontal_y)*(p.pos_y - current_grid_horizontal_y) );
				distance *= Data::get_cos_val(p.angle - current_angle);
				distance = distance < 1 ? 1 : distance; //division by 0 forbidden
				
				intersection_t is = {field_pos, current_grid_horizontal_x, current_grid_horizontal_y, distance, &m.map[field_pos.x][field_pos.y], true};
				
				Raydata::intersections[intersection_count] = is;
				intersection_count++;
				last_horizontal_distance = distance;
				
				/*
				//Debugging
				if (x == Debugger::current_x_pane_debug) {
					SDL_Rect r;
					r.w = 2;
					r.h = 2;
					r.x = current_grid_horizontal_x;
					r.y = current_grid_horizontal_y;
					SDL_SetRenderDrawColor(renderer, 255, 0, 255, 0);
					SDL_RenderFillRect(renderer, &r);
				}
				*/
			}
			
			if (current_grid_vertical_x >= 0 && current_grid_vertical_x / Field::width < m.field_num_x && current_grid_vertical_y >= 0 && current_grid_vertical_y / Field::height < m.field_num_y && last_vertical_distance < Player::view_distance) {
				
				SDL_Rect field_pos;
				field_pos.x = current_grid_vertical_x / Field::width;
				field_pos.y = current_grid_vertical_y / Field::width;
				
				
				
				double distance = sqrt( (p.pos_x - current_grid_vertical_x)*(p.pos_x - current_grid_vertical_x) + (p.pos_y - current_grid_vertical_y)*(p.pos_y - current_grid_vertical_y) );
				distance *= Data::get_cos_val(p.angle - current_angle);
				distance = distance < 1 ? 1 : distance; //division by 0 forbidden
				
				intersection_t is = {field_pos, current_grid_vertical_x, current_grid_vertical_y, distance, &m.map[field_pos.x][field_pos.y], false};
				
				Raydata::intersections[intersection_count] = is;
				intersection_count++;
				last_vertical_distance = distance;
				
				/*
				//Debugging
				if (x == Debugger::current_x_pane_debug) {
					SDL_Rect r;
					r.w = 2;
					r.h = 2;
					r.x = current_grid_vertical_x;
					r.y = current_grid_vertical_y;
					SDL_SetRenderDrawColor(renderer, 255, 0, 0, 0);
					SDL_RenderFillRect(renderer, &r);
				}
				*/
			}
			
			current_grid_horizontal_x += grid_stepsize_horizontal_x;
			current_grid_horizontal_y += grid_stepsize_horizontal_y;
			
			current_grid_vertical_x += grid_stepsize_vertical_x;
			current_grid_vertical_y += grid_stepsize_vertical_y;
		}
		
		// operator < used by default, shortest distance chosen
		std::sort( Raydata::intersections, Raydata::intersections + intersection_count );
		
		//this prevents vertical wall stripes on corners on horizontal walls
		if (grid_stepsize_horizontal_y < 0 && current_angle < 180) {
			for (int i = 0; i < intersection_count; i++) {
				if (i+1 < intersection_count) {
					if (!Raydata::intersections[i].horizontal_wall && Raydata::intersections[i+1].horizontal_wall && Raydata::intersections[i].field == Raydata::intersections[i+1].field) {
						double dist_weight = Raydata::intersections[i].distance / 100;
						double dist_dif = Raydata::intersections[i+1].distance - Raydata::intersections[i].distance;
						if (dist_dif < dist_weight) Raydata::intersections[i].horizontal_wall = true;
					}
				}
			}
		}
		
		int last_field_height = 0;//Raydata::intersections[0].field->size;
		int last_y_floorpos = Data::render_size_y;
		vector<Uint32>* last_floor_colors = Raydata::intersections[0].field->floor_color_values;
		for (int i = 0; i < intersection_count; i++) {
		
			/*
			//Debugging
			if (x == Debugger::Debugger::current_x_pane_debug) {
				cout << "int nr: " << i << "\tis hori: " << Raydata::intersections[i].horizontal_wall << "\tdistance: " << Raydata::intersections[i].distance << endl;
			}
			*/
			
			//floor y
			SDL_Rect r_floor_dest;
			double last_field_plane_height = (double)last_field_height/Raydata::intersections[i].distance * p.dist_player_to_plane + 1;
			double last_field_rear_edge_y_pos = (double)p.height / (Raydata::intersections[i].distance / p.dist_player_to_plane) + p.plane_y/2 - last_field_plane_height;
			
			r_floor_dest.y = last_field_rear_edge_y_pos;
			r_floor_dest.w = 1;
			r_floor_dest.h = 1;
			r_floor_dest.x = x;
			
			if (r_floor_dest.y < 0) r_floor_dest.y =  0;
			else if (r_floor_dest.y > Data::render_size_y) r_floor_dest.y = Data::render_size_y;
			
			//SDL_RenderDrawLine(renderer, x, r_floor_dest.y, x, last_y_floorpos);
			
			if (r_floor_dest.y < last_y_floorpos) {
				for (int y = r_floor_dest.y; y < last_y_floorpos; y++) {
					
					
					double straight_distance_to_floor = ((double)(p.height - last_field_height)/ (y - Player::plane_y/2)) * p.dist_player_to_plane;
					double cos_angle = p.angle - current_angle;
					cos_angle = cos_angle < 0 ? -cos_angle : cos_angle;
					double actual_distance_to_floor = (double)straight_distance_to_floor / Data::get_cos_val(cos_angle);
					
					
					SDL_Rect r_floor_texture;
					r_floor_texture.w = 1;
					r_floor_texture.h = 1;
					
					r_floor_texture.x = (int)(p.pos_x - actual_distance_to_floor * Data::get_cos_val(current_angle)) % Field::width;
					r_floor_texture.y = (int)(p.pos_y - actual_distance_to_floor * Data::get_sin_val(current_angle)) % Field::height;
					
					if (r_floor_texture.x < 0) r_floor_texture.x = -r_floor_texture.x;
					if (r_floor_texture.y < 0) r_floor_texture.y = -r_floor_texture.y;
					
					int pixel = y * Data::render_size_x + r_floor_dest.x;
					if (Raydata::intersections[i].distance < Player::view_distance) {
						
						//floor_pixels[pixel] = t.forest_floor_texdata.color_values[r_floor_texture.y * 64 + r_floor_texture.x];
						//floor_pixels[pixel] = Raydata::intersections[i].field->floor_color_values->at(r_floor_texture.y * 64 + r_floor_texture.x);
						floor_pixels[pixel] = last_floor_colors->at(r_floor_texture.y * 64 + r_floor_texture.x);
						if (Data::shader_activated) {
							t.shade_pixel(&floor_pixels[pixel], straight_distance_to_floor);
						}
						
					}
					
				}
				
				last_y_floorpos = r_floor_dest.y;
			}
			
			
			
			
			SDL_Rect r_wall_dest;
			if (Raydata::intersections[i].field->size > last_field_height) {
				//wall y
				double h_wall = (double)Raydata::intersections[i].field->size/Raydata::intersections[i].distance * p.dist_player_to_plane + 1;
				double y_wall_pos = (double)p.height / ((double)Raydata::intersections[i].distance / p.dist_player_to_plane) + (double)p.plane_y/2 - h_wall;
				SDL_Rect r_wall_dest;
				r_wall_dest.y = y_wall_pos;
				r_wall_dest.h = h_wall;//r_floor_dest.y - r_wall_dest.y;
				r_wall_dest.w = 1;
				r_wall_dest.x = x;
				
				if (r_wall_dest.y < last_y_floorpos) {
					
					
					SDL_Rect r_wall_texture;
					r_wall_texture.w = 1;
					r_wall_texture.h = Field::height; //hier texture eigene height angeben
					r_wall_texture.y = 0;
					if (Raydata::intersections[i].horizontal_wall)
						r_wall_texture.x = (int)Raydata::intersections[i].x_pos % Field::width;
					else
						r_wall_texture.x = (int)Raydata::intersections[i].y_pos % Field::width;
					
					
					if (r_wall_dest.y + r_wall_dest.h > last_y_floorpos) {
						double percentage = (double)(last_y_floorpos - r_wall_dest.y) / r_wall_dest.h;
						r_wall_dest.h = last_y_floorpos - r_wall_dest.y;
						r_wall_texture.h *= percentage;
						if (r_wall_texture.h == 0) r_wall_texture.h = 5;
					}
					
					if (r_wall_dest.y + r_wall_dest.h < last_y_floorpos) r_wall_dest.h = last_y_floorpos - r_wall_dest.y;
					
					SDL_Texture* wall_texture = Raydata::intersections[i].field->wall_texture;
					
					if (Data::shader_activated) {
						int old_range = Player::view_distance - 1;
						int new_range = 255 - 0; 
						Uint8 dist_weight = 255 - (((Raydata::intersections[i].distance - 0) * new_range) / old_range) + 0;
						
						if (Raydata::intersections[i].horizontal_wall) SDL_SetTextureColorMod(wall_texture, dist_weight/2, dist_weight/2, dist_weight/2);
						else SDL_SetTextureColorMod(wall_texture, dist_weight, dist_weight, dist_weight);
						
					} else {
						if (Raydata::intersections[i].horizontal_wall) SDL_SetTextureColorMod(wall_texture, 125, 125, 125);
						else SDL_SetTextureColorMod(wall_texture, 255, 255, 255);
					}
					
					//Debugging
					//if (Debugger::do_draw)SDL_RenderCopy(renderer, Raydata::intersections[i].field->wall_texture, &r_wall_texture, &r_wall_dest);
					SDL_RenderCopy(renderer, Raydata::intersections[i].field->wall_texture, &r_wall_texture, &r_wall_dest);
					
					last_y_floorpos = r_wall_dest.y;
					
				}
				
			}
			
			if (!Raydata::intersections[i].field->sprites.empty()) {
				
				for (vector<sprite_t>::iterator it = Raydata::intersections[i].field->sprites.begin(); it != Raydata::intersections[i].field->sprites.end(); it++) {
					
					
					double distance_sprite = sqrt( (p.pos_x - it->x_map_pos)*(p.pos_x - it->x_map_pos) + (p.pos_y - it->y_map_pos)*(p.pos_y - it->y_map_pos) );
					double h_sprite = (double)(it->tex_rect->h + Raydata::intersections[i].field->size)/distance_sprite * p.dist_player_to_plane + 1;
					double y_sprite_pos = (double)p.height / (distance_sprite / p.dist_player_to_plane) + (double)p.plane_y/2 - h_sprite;
					double h_pane = (double)(it->tex_rect->h)/distance_sprite * p.dist_player_to_plane + 1;
					
					
					/*
					double distance_sprite = sqrt( (p.pos_x - it->x_map_pos)*(p.pos_x - it->x_map_pos) + (p.pos_y - it->y_map_pos)*(p.pos_y - it->y_map_pos) );
					double h_pane = (double)(it->tex_rect->h)/distance_sprite * p.dist_player_to_plane + 1;
					double y_sprite_pos = (double)p.height / (distance_sprite / p.dist_player_to_plane) + (double)p.plane_y/2 - h_pane;
					
					cout << "p_x:" << p.pos_x << " p_y: " << p.pos_y << " s_x: " << it->x_map_pos << " s_y: " << it->y_map_pos << " distance: " <<distance_sprite << endl;
					*/
					
					SDL_Rect pane_rec;
					pane_rec.y = y_sprite_pos;
					pane_rec.x = x;
					pane_rec.w = 1;
					pane_rec.h = h_pane;
					
					
					//create lines
					double sprite_leftside_x = it->x_map_pos + it->tex_rect->w/2 * cos((270 - current_angle) * M_PI / 180);
					double sprite_leftside_y = it->y_map_pos + it->tex_rect->w/2 * sin((90 - current_angle) * M_PI / 180);
					
					double sprite_rightside_x = it->x_map_pos + it->tex_rect->w/2 * cos((90 - current_angle) * M_PI / 180);
					double sprite_rightside_y = it->y_map_pos + it->tex_rect->w/2 * sin((270 - current_angle) * M_PI / 180);
					
					double intersection_x = p.pos_x - Field::width * cos((current_angle) * M_PI / 180);
					double intersection_y = p.pos_y - Field::height * sin((current_angle) * M_PI / 180);
					
					
					//find intersection
					double ip_x, ip_y;
					double a1, a2, b1, b2, c1, c2;
					
					a1 = sprite_rightside_y - sprite_leftside_y;
					b1 = sprite_leftside_x - sprite_rightside_x;
					c1 = a1 * sprite_leftside_x + b1 * sprite_leftside_y;
					
					a2 = intersection_y - p.pos_y;
					b2 = p.pos_x - intersection_x;
					c2 = a2 * p.pos_x + b2 * p.pos_y;
					
					double det = a1 * b2 - a2 * b1;
					
					if (det == 0) {
						ip_x = Raydata::intersections[i].x_pos;
						ip_y = Raydata::intersections[i].y_pos;
					} else {
						ip_x = (b2 * c1 - b1 * c2)/det;
						ip_y = (a1 * c2 - a2 * c1)/det;
					}
					
					double x_dif;
					if (sprite_leftside_x > sprite_rightside_x) x_dif = sprite_leftside_x - sprite_rightside_x;
					else x_dif = sprite_rightside_x - sprite_leftside_x;
					
					double y_dif;
					if (sprite_leftside_y > sprite_rightside_y) y_dif = sprite_leftside_y - sprite_rightside_y;
					else y_dif = sprite_rightside_y - sprite_leftside_y;
					
					x_dif = x_dif < 0 ? -x_dif : x_dif;
					y_dif = y_dif < 0 ? -y_dif : y_dif;
					
					double sprite_dist = x_dif + y_dif;
					
					
					double ip_x_dif;
					if (sprite_leftside_x > ip_x) ip_x_dif = sprite_leftside_x - ip_x;
					else ip_x_dif = ip_x - sprite_leftside_x;
					
					double ip_y_dif;
					if (sprite_leftside_y > ip_y) ip_y_dif = sprite_leftside_y - ip_y;
					else ip_y_dif = ip_y - sprite_leftside_y;
					
					ip_x_dif = ip_x_dif < 0 ? -ip_x_dif : ip_x_dif;
					ip_y_dif = ip_y_dif < 0 ? -ip_y_dif : ip_y_dif;
					
					//cout << ip_x_dif + ip_y_dif << " " << x_dif + y_dif << endl;
					
					double percentage = (ip_x_dif + ip_y_dif) / (x_dif + y_dif);
					
					double x_tex = it->tex_rect->w * percentage;
					
					
					
					SDL_Rect tex_rec;
					tex_rec.x = (int)x_tex;//offset;
					tex_rec.y = 0;
					tex_rec.w = 1;
					tex_rec.h = it->tex_rect->h;
					
					
					
					if (pane_rec.y + pane_rec.h > last_y_floorpos) {
						double percentage = (double)(last_y_floorpos - pane_rec.y) / pane_rec.h;
						pane_rec.h = last_y_floorpos - pane_rec.y;
						tex_rec.h *= percentage;
						if (tex_rec.h == 0) tex_rec.h = 5;
					}
					
					
					
					sprite_drawdata_t sd = {&(*it), pane_rec, tex_rec};
					sprites.push_back(sd);
				}
			}
			
			last_floor_colors = Raydata::intersections[i].field->floor_color_values;
			last_field_height = Raydata::intersections[i].field->size;
		
		}
		
		
		/*
		//Debugging
		if (x == Debugger::Debugger::current_x_pane_debug) {
			if (Debugger::do_draw)SDL_RenderDrawLine(renderer, x, 0, x, Data::render_size_y);
		}
		*/
		
		current_angle += (double)Player::field_of_view/Player::plane_x;
		current_angle = current_angle >= 360 ? current_angle - 360 : current_angle;
	}
	//cout << render_count << endl;
	
	memcpy(t.floor_surface->pixels, floor_pixels, sizeof(floor_pixels));
	SDL_DestroyTexture(t.floor_texture);
	t.floor_texture = SDL_CreateTextureFromSurface(renderer, t.floor_surface);
	SDL_RenderCopy(renderer, t.floor_texture, NULL, NULL);
	
	std::reverse(sprites.begin(), sprites.end());
	for (vector<sprite_drawdata_t>::iterator it = sprites.begin(); it != sprites.end(); it++) {
		SDL_RenderCopy(renderer, it->sprite->tex, &it->tex_rec, &it->pane_rec);
	}
	
	
	
	//Debugging
	//if (Debugger::do_draw)SDL_RenderCopy(renderer, t.floor_texture, NULL, NULL);
}