diff options
| author | Stijn Buys <ingar@osirion.org> | 2008-07-23 15:16:56 +0000 | 
|---|---|---|
| committer | Stijn Buys <ingar@osirion.org> | 2008-07-23 15:16:56 +0000 | 
| commit | 426b766efbccdd8f5715de9526464db251fac30c (patch) | |
| tree | f1abfea7c1d4d4f1e97bd534d447cb6907576e2f /src/model/vertexarray.cc | |
| parent | 67517585e9b55967f5236ed5ebca77173eb2f2e3 (diff) | |
preparing for fragment rendering
Diffstat (limited to 'src/model/vertexarray.cc')
| -rw-r--r-- | src/model/vertexarray.cc | 66 | 
1 files changed, 30 insertions, 36 deletions
| diff --git a/src/model/vertexarray.cc b/src/model/vertexarray.cc index 27124fa..6a635eb 100644 --- a/src/model/vertexarray.cc +++ b/src/model/vertexarray.cc @@ -75,8 +75,9 @@ void VertexArray::add_sphere()  	math::Color white(1.0f, 1.0f, 1.0f);  	math::Vector3f v;  	math::Vector3f n; -	math::Vector3f tex; -	int count; +	float texx, texy; + +	int quad_count = 0;  	// add sphere  	for (int j=0; j < (SPHERESEGMENTS-1) / 2; j++) { @@ -88,18 +89,22 @@ void VertexArray::add_sphere()  			v = math::Vector3f(r*costable[i], r*sintable[i], costable[j]);  			n = v;  			n.normalize(); -			tex.assign((float)i/(float)(SPHERESEGMENTS-1), -costable[j]/2 + 0.5f , 0); -			add_vertex(v, n, white, tex); +			texx = (float)i/(float)(SPHERESEGMENTS-1); +			texy = -costable[j]/2 + 0.5f; +			add_vertex(v, n, white, texx, texy);  			v = math::Vector3f(r1*costable[i], r1*sintable[i], costable[j+1]);  			n = v;  			n.normalize();			 -			tex.assign((float)i/(float)(SPHERESEGMENTS-1), -costable[j+1]/2 + 0.5f, 0); -			add_vertex(v, n, white, tex); -			count +=2; +			texx = (float)i/(float)(SPHERESEGMENTS-1); +			texy = -costable[j+1]/2 + 0.5f; +			add_vertex(v, n, white, texx, texy); + +			quad_count++;  		} -		 +		quad_count--;  	} +	  	// add inside-out sphere  	for (int j=0; j < (SPHERESEGMENTS-1) / 2; j++) { @@ -112,15 +117,16 @@ void VertexArray::add_sphere()  			v = math::Vector3f(r*costable[i], r*sintable[i], costable[j]);  			n = v;  			n.normalize(); -			tex.assign(1-(float)i/(float)(SPHERESEGMENTS-1), -costable[j]/2 + 0.5f , 0); -			add_vertex(v, n, white, tex); +			texx = 1-(float)i/(float)(SPHERESEGMENTS-1); +			texy =  -costable[j]/2 + 0.5f; +			add_vertex(v, n, white, texx, texy);  			v = math::Vector3f(r1*costable[i], r1*sintable[i], costable[j+1]);  			n = v;  			n.normalize();			 -			tex.assign(1-(float)i/(float)(SPHERESEGMENTS-1), -costable[j+1]/2 + 0.5f, 0); -			add_vertex(v, n, white, tex); -			count +=2; +			texx = 1-(float)i/(float)(SPHERESEGMENTS-1); +			texy = -costable[j+1]/2 + 0.5f; +			add_vertex(v, n, white, texx, texy);  		}  	} @@ -129,10 +135,13 @@ void VertexArray::add_sphere()  	delete[] costable;  } -size_t VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color) { +size_t VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color, float tex_x, float tex_y) +{  	if (vertex_index + 3 >= vertex_size) { -		con_warn << "VertexArray overflow!" << std::endl; -		vertex_overflow = true; +		if (!vertex_overflow) { +			con_warn << "VertexArray overflow!" << std::endl; +			vertex_overflow = true; +		}  		return 0;  	} @@ -145,31 +154,16 @@ size_t VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n,  	vertex_color[vertex_index+1] = color.g;  	vertex_color[vertex_index+2] = color.b; +	vertex_texture[vertex_index] = tex_x; +	vertex_texture[vertex_index+1] = tex_y; +	// reserved +	vertex_texture[vertex_index+2] = 0; +  	vertex_index += 3;  	return 1;  } -size_t VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color, math::Vector3f const &tex) { -	if (vertex_index + 3 >= vertex_size) { -		con_warn << "VertexArray overflow!" << std::endl; -		vertex_overflow = true; -		return 0; -	} - -	for (int i = 0; i < 3; i ++) { -		vertex_vertex[vertex_index+i] = v[i]; -		vertex_normal[vertex_index+i] = n[i]; -		vertex_texture[vertex_index+i] = tex[i]; -	} - -	vertex_color[vertex_index] = color.r; -	vertex_color[vertex_index+1] = color.g; -	vertex_color[vertex_index+2] = color.b; - -	vertex_index += 3; -	return 1; -}  } | 
