Esempio n. 1
0
void display(void) {
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glLoadIdentity();
    gluLookAt(0.0,0.0,10.0,
              0.0,0.0,-1.0,
              0.0f,1.0f,0.0f);
    
    
    glRotatef(a,0,1,0);
    //you send loc as your attribute "height" to vertex shader. Vertex specified in glVertex calls is available to access in vertex shader as gl_Vertex
    glBegin(GL_TRIANGLE_STRIP);
    glVertexAttrib1f(loc,2.0);
    glVertex2f(-1,1);
    
    glVertexAttrib1f(loc,2.0);
    glVertex2f(1,1);
    
    glVertexAttrib1f(loc,-2.0);
    glVertex2f(-1,-1);
    
    glVertexAttrib1f(loc,-2.0);
    glVertex2f(1,-1);
    
    glEnd();
    
    
    a+=0.1;
    
    glutSwapBuffers();
}
void
GLSLProgram::SetAttributeVariable(char* name, float val)
{
	int loc;
	if ((loc = GetAttributeLocation(name)) >= 0)
	{
		this->Use();
		glVertexAttrib1f(loc, val);
	}
};
Esempio n. 3
0
static void display(void)
{
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -5.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
         //查询vertex shader属性变量VertexTemp,并对它进行设置,每个vertex需要指定一个属性
         GLint tempLoc = glGetAttribLocationARB(ProgramObject, "VertexTemp");
         glBegin(GL_TRIANGLES);
                   glVertexAttrib1f(tempLoc, 0.0f);        
                   glVertex3f(1.0f,0.0f,0.0f);
                   glVertexAttrib1f(tempLoc, 0.5f);
                   glVertex3f(-1.0f,0.0f,0.0f);
                   glVertexAttrib1f(tempLoc, 1.0f);
                   glVertex3f(0.0f,1.0f,0.0f);
         glEnd();
    glFlush();
    glutSwapBuffers();
}
Esempio n. 4
0
	bool ShaderManager :: SetAttributeFloat ( const char * name, float value )
	{
		int location = glGetAttribLocation ( Program, name );

		if ( location < 0 )
			return false;

		glVertexAttrib1f ( location, value );

		return true;
	}
Esempio n. 5
0
// Send out a normal, texture coordinate, vertex coordinate, and an optional custom attribute.
void TParametricSurface::Vertex(vec2 domain)
{
    vec3 p0, p1, p2, p3;
    vec3 normal;
    float u = domain.u;
    float v = domain.v;

    Eval(domain, p0);
    vec2 z1(u + du/2, v);
    Eval(z1, p1);
    vec2 z2(u + du/2 + du, v);
    Eval(z2, p3);

    if (flipped) {
        vec2 z3(u + du/2, v - dv);
        Eval(z3, p2);
    } else {
        vec2 z4(u + du/2, v + dv);
        Eval(z4, p2);
    }

    const float epsilon = 0.00001f;

    vec3 tangent = p3 - p1;
    vec3 binormal = p2 - p1;
    normal = cross(tangent, binormal);
    if (normal.magnitude() < epsilon)
        normal = p0;
    normal.unitize();

    if (tangentLoc != -1)
    {
        if (tangent.magnitude() < epsilon)
            tangent = cross(binormal, normal);
        tangent.unitize();
        glVertexAttrib(tangentLoc, tangent);
    }

    if (binormalLoc != -1)
    {
        binormal.unitize();
        glVertexAttrib(binormalLoc, -binormal);
    }

    if (CustomAttributeLocation() != -1)
        glVertexAttrib1f(CustomAttributeLocation(), CustomAttributeValue(domain));

    glNormal(normal);
    glTexCoord(domain);
    glVertex(p0);
}
Esempio n. 6
0
static int gl_SetSpriteLight(AActor *self, fixed_t x, fixed_t y, fixed_t z, subsector_t * subsec, 
                              int lightlevel, int rellight, FColormap * cm, float alpha, 
							  PalEntry ThingColor, bool weapon)
{
	float r,g,b;
	float result[4]; // Korshun.

	gl_GetLightColor(lightlevel, rellight, cm, &r, &g, &b, weapon);
	bool res = gl_GetSpriteLight(self, x, y, z, subsec, cm? cm->colormap : 0, result);
	if (!res || glset.lightmode == 8)
	{
		r *= ThingColor.r/255.f;
		g *= ThingColor.g/255.f;
		b *= ThingColor.b/255.f;
		glColor4f(r, g, b, alpha);
		if (glset.lightmode == 8) 
		{
			glVertexAttrib1f(VATTR_LIGHTLEVEL, gl_CalcLightLevel(lightlevel, rellight, weapon) / 255.0f); // Korshun.
			gl_RenderState.SetDynLight(result[0], result[1], result[2]);
		}
		return lightlevel;
	}
	else
	{
		// Note: Due to subtractive lights the values can easily become negative so we have to clamp both
		// at the low and top end of the range!
		r = clamp<float>(result[0]+r, 0, 1.0f);
		g = clamp<float>(result[1]+g, 0, 1.0f);
		b = clamp<float>(result[2]+b, 0, 1.0f);

		float dlightlevel = r*77 + g*143 + b*35;

		r *= ThingColor.r/255.f;
		g *= ThingColor.g/255.f;
		b *= ThingColor.b/255.f;

		glColor4f(r, g, b, alpha);		

		if (dlightlevel == 0) return 0;

		if (glset.lightmode&2 && dlightlevel<192.f) 
		{
			return xs_CRoundToInt(192.f - (192.f - dlightlevel) / 1.95f);
		}
		else
		{
			return xs_CRoundToInt(dlightlevel);
		}
	}
}
Esempio n. 7
0
void content (void)
{
	glColor3ub (255,0,0);

	// how about vector attribute
	glBegin(GL_TRIANGLE_STRIP);

		glVertexAttrib1f(temp_loc,60);
		glVertex2f(-1,1);

		glVertexAttrib1f(temp_loc,20);
		glVertex2f(1,1);

		glVertexAttrib1f(temp_loc,10);
		glVertex2f(-1,-1);

		glVertexAttrib1f(temp_loc,95);
		glVertex2f(1,-1);

	glEnd();

	glutSwapBuffers();
}
void display(void)
{
  /*clear all pixels*/
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
  //Take care of any mouse rotations or panning
    mv = LookAt(vec4(0, 0, 10+z_distance, 1.0), vec4(0, 0, 0, 1.0), vec4(0, 1, 0, 0.0));

	mv = mv * RotateX(view_rotx) * RotateY(view_roty) * RotateZ(view_rotz);

	glUniformMatrix4fv(model_view, 1, GL_TRUE, mv);
	
	
	//You need to send some vertex attributes and uniform variables here
	glUniform4fv(ambient_light, 1, vec4(0.2, 0.2, 0.2, 1));
	glUniform4fv(light_color, 1, vec4(1, 1, 1, 1));
	glUniform4fv(light_position, 1, mv*vec4(50, 50, 50, 1));		// Light will follow the object (Because of mv)
	
	glVertexAttrib4fv(vAmbientDiffuseColor, vec4(0, 0.5, 0, 1));
    glVertexAttrib4fv(vSpecularColor, vec4(1, 1, 1, 1));
	glVertexAttrib1f(vSpecularExponent, 10);

	if(mode == 0){
		glBindVertexArray( vao[0] );
		glDrawArrays( GL_TRIANGLES, 0, spherevertcount );    // draw the sphere 
	}else{
		//WARNING:
		//Nvidia kludge: If you want the teapot to show up correctly, make sure that 
		//vPosition is the first attribute listed in your vertex shader, and vNormal
		//is the 3rd attribute listed.  Not sure what ATI cards will do with this
		glBindVertexArray(0);
		glutSolidTeapot(2); //not very bandwidth efficient
	}

    
    glFlush();
  /*start processing buffered OpenGL routines*/
  glutSwapBuffers();
}
Esempio n. 9
0
void VecSliderMenuItem::DrawNormalVecView(const Camera& curCamera, 
	float x, float y, float w, float h, const vec3& normal)
{
	GLint mvpLoc = g_normalViewShader->m_uniforms[BIND_Mvp];
	GLint colorLoc = g_normalViewShader->m_attrs[GEOM_Color];
	GLint posLoc = g_normalViewShader->m_attrs[GEOM_Pos];
	GLint coordLoc = g_normalViewShader->m_attrs[GEOM_Uv];
	GLint stippleLoc = g_normalViewShader->m_custom[NORMALBIND_Stipple];

	ViewportState vpState(x, g_screen.m_height-y-h, w, h);
	ScissorState scState(x, g_screen.m_height-y-h, w, h);

	glClearColor(0.05f,0.05f,0.05f,1.f);
	glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

	Camera localcamera = curCamera;
	localcamera.SetPos(-4.f * curCamera.GetViewframe().m_fwd);
	localcamera.Compute();
	mat4 proj = Compute3DProj(30.f, w/h, 0.1, 5);
	mat4 mvp = proj * localcamera.GetView();

	glUseProgram(g_normalViewShader->m_program);
	glUniformMatrix4fv(mvpLoc, 1, 0, mvp.m);
	glUniform1f(stippleLoc, 0);

	glBegin(GL_LINES);
	// axes
	glVertexAttrib3f(colorLoc, 1, 0, 0);
	glVertexAttrib1f(coordLoc, 0); glVertexAttrib3f(posLoc, 0, 0, 0);
	glVertexAttrib1f(coordLoc, 1); glVertexAttrib3f(posLoc, 1, 0, 0);
	
	glVertexAttrib3f(colorLoc, 0.2, 0, 0);
	glVertexAttrib1f(coordLoc, 0); glVertexAttrib3f(posLoc, 0, 0, 0);
	glVertexAttrib1f(coordLoc, 1); glVertexAttrib3f(posLoc, -1, 0, 0);
	
	glVertexAttrib3f(colorLoc, 0, 1, 0);
	glVertexAttrib1f(coordLoc, 0); glVertexAttrib3f(posLoc, 0, 0, 0);
	glVertexAttrib1f(coordLoc, 1); glVertexAttrib3f(posLoc, 0, 1, 0);
	
	glVertexAttrib3f(colorLoc, 0, 0.2, 0);
	glVertexAttrib1f(coordLoc, 0); glVertexAttrib3f(posLoc, 0, 0, 0);
	glVertexAttrib1f(coordLoc, 1); glVertexAttrib3f(posLoc, 0, -1, 0);
	
	glVertexAttrib3f(colorLoc, 0, 0, 1);
	glVertexAttrib1f(coordLoc, 0); glVertexAttrib3f(posLoc, 0, 0, 0);
	glVertexAttrib1f(coordLoc, 1); glVertexAttrib3f(posLoc, 0, 0, 1);
	
	glVertexAttrib3f(colorLoc, 0, 0, 0.2);
	glVertexAttrib1f(coordLoc, 0); glVertexAttrib3f(posLoc, 0, 0, 0);
	glVertexAttrib1f(coordLoc, 1); glVertexAttrib3f(posLoc, 0, 0, -1);

	// vector
	glVertexAttrib3f(colorLoc, 0.7, 0.7, 0.7);
	glVertexAttrib3f(posLoc, 0, 0, 0);
	glVertexAttrib3fv(posLoc, &normal.x);
	glEnd();

	// helper lines
	static Color kColNeg = {0.2,0.2,0.2}, kColPos = {0.4,0.4,0.4};

	glUniform1f(stippleLoc, 0.1f);
	glBegin(GL_LINES);
	glVertexAttrib3fv(colorLoc, normal.x > 0 ? &kColPos.r : &kColNeg.r); 
	glVertexAttrib1f(coordLoc, 0); glVertexAttrib3f(posLoc, 0, normal.y, 0);
	glVertexAttrib1f(coordLoc, normal.x); glVertexAttrib3f(posLoc, normal.x, normal.y, 0);

	glVertexAttrib3fv(colorLoc, normal.y > 0 ? &kColPos.r : &kColNeg.r); 
	glVertexAttrib1f(coordLoc, 0); glVertexAttrib3f(posLoc, normal.x, 0, 0);
	glVertexAttrib1f(coordLoc, normal.y); glVertexAttrib3f(posLoc, normal.x, normal.y, 0);
	
	glVertexAttrib3fv(colorLoc, normal.z > 0 ? &kColPos.r : &kColNeg.r); 
	glVertexAttrib1f(coordLoc, 0); glVertexAttrib3f(posLoc, normal.x, normal.y, 0);
	glVertexAttrib1f(coordLoc, normal.z); glVertexAttrib3fv(posLoc, &normal.x);
	
	glEnd();

	glLineWidth(1.f);
	checkGlError("menu_DrawNormalVecView");
}
Esempio n. 10
0
void GLGSRender::EnableVertexData(bool indexed_draw)
{
	static u32 offset_list[m_vertex_count];
	u32 cur_offset = 0;

	const u32 data_offset = indexed_draw ? 0 : m_draw_array_first;

	for(u32 i=0; i<m_vertex_count; ++i)
	{
		offset_list[i] = cur_offset;

		if(!m_vertex_data[i].IsEnabled() || !m_vertex_data[i].addr) continue;

		const size_t item_size = m_vertex_data[i].GetTypeSize() * m_vertex_data[i].size;
		const size_t data_size = m_vertex_data[i].data.size() - data_offset * item_size;
		const u32 pos = m_vdata.size();

		cur_offset += data_size;
		m_vdata.resize(m_vdata.size() + data_size);
		memcpy(&m_vdata[pos], &m_vertex_data[i].data[data_offset * item_size], data_size);
	}

	m_vao.Create();
	m_vao.Bind();
	checkForGlError("initializing vao");

	m_vbo.Create(indexed_draw ? 2 : 1);
	m_vbo.Bind(0);
	m_vbo.SetData(&m_vdata[0], m_vdata.size());

	if(indexed_draw)
	{
		m_vbo.Bind(GL_ELEMENT_ARRAY_BUFFER, 1);
		m_vbo.SetData(GL_ELEMENT_ARRAY_BUFFER, &m_indexed_array.m_data[0], m_indexed_array.m_data.size());
	}

	checkForGlError("initializing vbo");

#if	DUMP_VERTEX_DATA
	rFile dump("VertexDataArray.dump", rFile::write);
#endif

	for(u32 i=0; i<m_vertex_count; ++i)
	{
		if(!m_vertex_data[i].IsEnabled()) continue;

#if	DUMP_VERTEX_DATA
		dump.Write(wxString::Format("VertexData[%d]:\n", i));
		switch(m_vertex_data[i].type)
		{
		case CELL_GCM_VERTEX_S1:
			for(u32 j = 0; j<m_vertex_data[i].data.size(); j+=2)
			{
				dump.Write(wxString::Format("%d\n", *(u16*)&m_vertex_data[i].data[j]));
				if(!(((j+2) / 2) % m_vertex_data[i].size)) dump.Write("\n");
			}
		break;

		case CELL_GCM_VERTEX_F:
			for(u32 j = 0; j<m_vertex_data[i].data.size(); j+=4)
			{
				dump.Write(wxString::Format("%.01f\n", *(float*)&m_vertex_data[i].data[j]));
				if(!(((j+4) / 4) % m_vertex_data[i].size)) dump.Write("\n");
			}
		break;

		case CELL_GCM_VERTEX_SF:
			for(u32 j = 0; j<m_vertex_data[i].data.size(); j+=2)
			{
				dump.Write(wxString::Format("%.01f\n", *(float*)&m_vertex_data[i].data[j]));
				if(!(((j+2) / 2) % m_vertex_data[i].size)) dump.Write("\n");
			}
		break;

		case CELL_GCM_VERTEX_UB:
			for(u32 j = 0; j<m_vertex_data[i].data.size(); ++j)
			{
				dump.Write(wxString::Format("%d\n", m_vertex_data[i].data[j]));
				if(!((j+1) % m_vertex_data[i].size)) dump.Write("\n");
			}
		break;

		case CELL_GCM_VERTEX_S32K:
			for(u32 j = 0; j<m_vertex_data[i].data.size(); j+=2)
			{
				dump.Write(wxString::Format("%d\n", *(u16*)&m_vertex_data[i].data[j]));
				if(!(((j+2) / 2) % m_vertex_data[i].size)) dump.Write("\n");
			}
		break;
		
		// case CELL_GCM_VERTEX_CMP:
		
		case CELL_GCM_VERTEX_UB256:
			for(u32 j = 0; j<m_vertex_data[i].data.size(); ++j)
			{
				dump.Write(wxString::Format("%d\n", m_vertex_data[i].data[j]));
				if(!((j+1) % m_vertex_data[i].size)) dump.Write("\n");
			}
		break;

		default:
			ConLog.Error("Bad cv type! %d", m_vertex_data[i].type);
		return;
		}

		dump.Write("\n");
#endif

		static const u32 gl_types[] =
		{
			GL_SHORT,
			GL_FLOAT,
			GL_HALF_FLOAT,
			GL_UNSIGNED_BYTE,
			GL_SHORT,
			GL_UNSIGNED_BYTE,
		};

		static const bool gl_normalized[] =
		{
			true,
			false,
			false,
			true,
			false,
			false,
		};

		if(m_vertex_data[i].type >= 1 && m_vertex_data[i].type <= 7)
		{
			if(!m_vertex_data[i].addr)
			{
				switch(m_vertex_data[i].type)
				{
				case CELL_GCM_VERTEX_S32K:
				case CELL_GCM_VERTEX_S1:
					switch(m_vertex_data[i].size)
					{
					case 1: glVertexAttrib1s(i, (GLshort&)m_vertex_data[i].data[0]); break;
					case 2: glVertexAttrib2sv(i, (GLshort*)&m_vertex_data[i].data[0]); break;
					case 3: glVertexAttrib3sv(i, (GLshort*)&m_vertex_data[i].data[0]); break;
					case 4: glVertexAttrib4sv(i, (GLshort*)&m_vertex_data[i].data[0]); break;
					}
				break;

				case CELL_GCM_VERTEX_F:
					switch(m_vertex_data[i].size)
					{
					case 1: glVertexAttrib1f(i, (GLfloat&)m_vertex_data[i].data[0]); break;
					case 2: glVertexAttrib2fv(i, (GLfloat*)&m_vertex_data[i].data[0]); break;
					case 3: glVertexAttrib3fv(i, (GLfloat*)&m_vertex_data[i].data[0]); break;
					case 4: glVertexAttrib4fv(i, (GLfloat*)&m_vertex_data[i].data[0]); break;
					}
				break;

				case CELL_GCM_VERTEX_CMP:
				case CELL_GCM_VERTEX_UB:
					glVertexAttrib4ubv(i, (GLubyte*)&m_vertex_data[i].data[0]);
				break;
				}

				checkForGlError("glVertexAttrib");
			}
			else
			{
				u32 gltype = gl_types[m_vertex_data[i].type - 1];
				bool normalized = gl_normalized[m_vertex_data[i].type - 1];

				glEnableVertexAttribArray(i);
				checkForGlError("glEnableVertexAttribArray");
				glVertexAttribPointer(i, m_vertex_data[i].size, gltype, normalized, 0, (void*)offset_list[i]);
				checkForGlError("glVertexAttribPointer");
			}
		}
	}
}
Esempio n. 11
0
void Shader::SetAttribute(const char* var, float v)
{
	int id = GetAttributeId(var);
	if(id >= 0)
		glVertexAttrib1f(id, v);
}
// Attributes
//
// 1 component
void ShaderProgram::setAttribute(GLint index, GLfloat v1)
{
	glVertexAttrib1f(index, v1);
}
Esempio n. 13
0
int InitGL(GLvoid)										// All Setup For OpenGL Goes Here
{
	g_fTime=0;
	glewInit();
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	gluPerspective( 70, GLdouble( x_res ) / y_res, 0.01, 10000.0 );

	{	glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
		picture surface( "D://tex0.bmp" );
		GLuint texture_id;
		glActiveTexture(GL_TEXTURE0);
		glGenTextures( 1, &texture_id );
		glBindTexture( GL_TEXTURE_2D, texture_id );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface.xsize, surface.ysize, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface.content );}
	{	glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
		picture surface( "D://tex1.bmp" );
		GLuint texture_id;
		glActiveTexture(GL_TEXTURE1);
		glGenTextures( 1, &texture_id );
		glBindTexture( GL_TEXTURE_2D, texture_id );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface.xsize, surface.ysize, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface.content );}
	{	glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
		picture surface( "D://tex2.bmp" );
		GLuint texture_id;
		glActiveTexture(GL_TEXTURE2);
		glGenTextures( 1, &texture_id );
		glBindTexture( GL_TEXTURE_2D, texture_id );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface.xsize, surface.ysize, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface.content );}
	{	glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
		picture surface( "D://tex3.bmp" );
		GLuint texture_id;
		glActiveTexture(GL_TEXTURE3);
		glGenTextures( 1, &texture_id );
		glBindTexture( GL_TEXTURE_2D, texture_id );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface.xsize, surface.ysize, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface.content );}
	
	GLuint prog=load_program("D://program2.vert","D://program2.frag");
	glUseProgram(prog);

	GLint texture_location = glGetUniformLocation( prog, "tex1" );
    if( texture_location == -1 ) exit_error( "Variable konnte im aktuellen Unterprogramm nicht erfasst werden.\n" );
    glUniform1i( texture_location, 0 );
	texture_location = glGetUniformLocation( prog, "tex2" );
    if( texture_location == -1 ) exit_error( "Variable konnte im aktuellen Unterprogramm nicht erfasst werden.\n" );
    glUniform1i( texture_location, 1 );
	texture_location = glGetUniformLocation( prog, "tex3" );
    if( texture_location == -1 ) exit_error( "Variable konnte im aktuellen Unterprogramm nicht erfasst werden.\n" );
    glUniform1i( texture_location, 2 );
	texture_location = glGetUniformLocation( prog, "tex4" );
    if( texture_location == -1 ) exit_error( "Variable konnte im aktuellen Unterprogramm nicht erfasst werden.\n" );
    glUniform1i( texture_location, 3 );

	//load_gl_texture("D://tex0.bmp",GL_TEXTURE0,"tex1",prog);
	//load_gl_texture("D://tex1.bmp",GL_TEXTURE1,"tex2",prog);
	//load_gl_texture("D://tex2.bmp",GL_TEXTURE2,"tex3",prog);
	//load_gl_texture("D://tex3.bmp",GL_TEXTURE3,"tex4",prog);

	g_hDominantLightDirection = glGetUniformLocation( prog, "DominantLightDirection" );
    //if( g_hDominantLightDirection == -1 ) exit_error( "Variable 'DominantLightDirection' konnte im aktuellen Unterprogramm nicht erfasst werden.\n" );
    glUniform3f( g_hTime, 0, 0, 0 );

	g_hW1 = glGetAttribLocation( prog, "w1" );
    if( g_hW1 == -1 ) exit_error( "Variable 'DominantLightDirection' konnte im aktuellen Unterprogramm nicht erfasst werden.\n" );
    glVertexAttrib1f( g_hW1, 0);

	g_hW2 = glGetAttribLocation( prog, "w2" );
    if( g_hW2 == -1 ) exit_error( "Variable 'DominantLightDirection' konnte im aktuellen Unterprogramm nicht erfasst werden.\n" );
    glVertexAttrib1f( g_hW2, 0);

	g_hW3 = glGetAttribLocation( prog, "w3" );
    if( g_hW3 == -1 ) exit_error( "Variable 'DominantLightDirection' konnte im aktuellen Unterprogramm nicht erfasst werden.\n" );
    glVertexAttrib1f( g_hW3, 0);

	g_hW4 = glGetAttribLocation( prog, "w4" );
    if( g_hW4 == -1 ) exit_error( "Variable 'DominantLightDirection' konnte im aktuellen Unterprogramm nicht erfasst werden.\n" );
    glVertexAttrib1f( g_hW4, 0);

	g_Landscape = new Landscape4Tex(257,257,"D://height_map.bmp");
	g_DominantDirectionalLight= new DominantDirectionalLight();
	g_DominantDirectionalLight->m_Position=vertex(0,10,0);
	g_DominantDirectionalLight->m_Direction=vector(0,-1,0);
	
	matrix a;
	a.translate(0.0f,0.0f,-15.0f);

	g_Landscape->Transform(a);
	g_DominantDirectionalLight->Transform(a);

	g.clear();
 
	return TRUE;										// Initialization Went OK
}
Esempio n. 14
0
void GraphicsContext3D::vertexAttrib1f(GC3Duint index, GC3Dfloat v0)
{
    makeContextCurrent();
    glVertexAttrib1f(index, v0);
}
Esempio n. 15
0
//--------------------------------------------------------------
void ofShader::setAttribute1f(GLint location, float v1)  const{
	if(bLoaded)
		glVertexAttrib1f(location, v1);
}
	void AttributeVariable::set(GLfloat f0_)
	{
		glVertexAttrib1f(_location, f0_);
	}
Esempio n. 17
0
void ccShader::setAttrib1f(int loc, float value)
{
	glVertexAttrib1f(loc,value);
}
Esempio n. 18
0
void Shader::setFloatAttribute(const std::string& _name, float _f) const
{
	assert(programObj_ != 0);
	glVertexAttrib1f(getAttributeLocation(_name.c_str()), _f);
}
Esempio n. 19
0
uintptr_t processFn(struct fnargs* args, char* parg) {
	uintptr_t ret = 0;
	switch (args->fn) {
	case glfnUNDEFINED:
		abort(); // bad glfn
		break;
	case glfnActiveTexture:
		glActiveTexture((GLenum)args->a0);
		break;
	case glfnAttachShader:
		glAttachShader((GLint)args->a0, (GLint)args->a1);
		break;
	case glfnBindAttribLocation:
		glBindAttribLocation((GLint)args->a0, (GLint)args->a1, (GLchar*)args->a2);
		break;
	case glfnBindBuffer:
		glBindBuffer((GLenum)args->a0, (GLuint)args->a1);
		break;
	case glfnBindFramebuffer:
		glBindFramebuffer((GLenum)args->a0, (GLint)args->a1);
		break;
	case glfnBindRenderbuffer:
		glBindRenderbuffer((GLenum)args->a0, (GLint)args->a1);
		break;
	case glfnBindTexture:
		glBindTexture((GLenum)args->a0, (GLint)args->a1);
		break;
	case glfnBlendColor:
		glBlendColor(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3);
		break;
	case glfnBlendEquation:
		glBlendEquation((GLenum)args->a0);
		break;
	case glfnBlendEquationSeparate:
		glBlendEquationSeparate((GLenum)args->a0, (GLenum)args->a1);
		break;
	case glfnBlendFunc:
		glBlendFunc((GLenum)args->a0, (GLenum)args->a1);
		break;
	case glfnBlendFuncSeparate:
		glBlendFuncSeparate((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLenum)args->a3);
		break;
	case glfnBufferData:
		glBufferData((GLenum)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg, (GLenum)args->a2);
		break;
	case glfnBufferSubData:
		glBufferSubData((GLenum)args->a0, (GLint)args->a1, (GLsizeiptr)args->a2, (GLvoid*)parg);
		break;
	case glfnCheckFramebufferStatus:
		ret = glCheckFramebufferStatus((GLenum)args->a0);
		break;
	case glfnClear:
		glClear((GLenum)args->a0);
		break;
	case glfnClearColor:
		glClearColor(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3);
		break;
	case glfnClearDepthf:
		glClearDepthf(*(GLfloat*)&args->a0);
		break;
	case glfnClearStencil:
		glClearStencil((GLint)args->a0);
		break;
	case glfnColorMask:
		glColorMask((GLboolean)args->a0, (GLboolean)args->a1, (GLboolean)args->a2, (GLboolean)args->a3);
		break;
	case glfnCompileShader:
		glCompileShader((GLint)args->a0);
		break;
	case glfnCompressedTexImage2D:
		glCompressedTexImage2D((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLsizeiptr)args->a6, (GLvoid*)parg);
		break;
	case glfnCompressedTexSubImage2D:
		glCompressedTexSubImage2D((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLenum)args->a6, (GLsizeiptr)args->a7, (GLvoid*)parg);
		break;
	case glfnCopyTexImage2D:
		glCopyTexImage2D((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLint)args->a6, (GLint)args->a7);
		break;
	case glfnCopyTexSubImage2D:
		glCopyTexSubImage2D((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLint)args->a6, (GLint)args->a7);
		break;
	case glfnCreateProgram:
		ret = glCreateProgram();
		break;
	case glfnCreateShader:
		ret = glCreateShader((GLenum)args->a0);
		break;
	case glfnCullFace:
		glCullFace((GLenum)args->a0);
		break;
	case glfnDeleteBuffer:
		glDeleteBuffers(1, (const GLuint*)(&args->a0));
		break;
	case glfnDeleteFramebuffer:
		glDeleteFramebuffers(1, (const GLuint*)(&args->a0));
		break;
	case glfnDeleteProgram:
		glDeleteProgram((GLint)args->a0);
		break;
	case glfnDeleteRenderbuffer:
		glDeleteRenderbuffers(1, (const GLuint*)(&args->a0));
		break;
	case glfnDeleteShader:
		glDeleteShader((GLint)args->a0);
		break;
	case glfnDeleteTexture:
		glDeleteTextures(1, (const GLuint*)(&args->a0));
		break;
	case glfnDepthFunc:
		glDepthFunc((GLenum)args->a0);
		break;
	case glfnDepthMask:
		glDepthMask((GLboolean)args->a0);
		break;
	case glfnDepthRangef:
		glDepthRangef(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1);
		break;
	case glfnDetachShader:
		glDetachShader((GLint)args->a0, (GLint)args->a1);
		break;
	case glfnDisable:
		glDisable((GLenum)args->a0);
		break;
	case glfnDisableVertexAttribArray:
		glDisableVertexAttribArray((GLint)args->a0);
		break;
	case glfnDrawArrays:
		glDrawArrays((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2);
		break;
	case glfnDrawElements:
		glDrawElements((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (void*)args->a3);
		break;
	case glfnEnable:
		glEnable((GLenum)args->a0);
		break;
	case glfnEnableVertexAttribArray:
		glEnableVertexAttribArray((GLint)args->a0);
		break;
	case glfnFinish:
		glFinish();
		break;
	case glfnFlush:
		glFlush();
		break;
	case glfnFramebufferRenderbuffer:
		glFramebufferRenderbuffer((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint)args->a3);
		break;
	case glfnFramebufferTexture2D:
		glFramebufferTexture2D((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4);
		break;
	case glfnFrontFace:
		glFrontFace((GLenum)args->a0);
		break;
	case glfnGenBuffer:
		glGenBuffers(1, (GLuint*)&ret);
		break;
	case glfnGenFramebuffer:
		glGenFramebuffers(1, (GLuint*)&ret);
		break;
	case glfnGenRenderbuffer:
		glGenRenderbuffers(1, (GLuint*)&ret);
		break;
	case glfnGenTexture:
		glGenTextures(1, (GLuint*)&ret);
		break;
	case glfnGenerateMipmap:
		glGenerateMipmap((GLenum)args->a0);
		break;
	case glfnGetActiveAttrib:
		glGetActiveAttrib(
			(GLuint)args->a0,
			(GLuint)args->a1,
			(GLsizei)args->a2,
			NULL,
			(GLint*)&ret,
			(GLenum*)args->a3,
			(GLchar*)parg);
		break;
	case glfnGetActiveUniform:
		glGetActiveUniform(
			(GLuint)args->a0,
			(GLuint)args->a1,
			(GLsizei)args->a2,
			NULL,
			(GLint*)&ret,
			(GLenum*)args->a3,
			(GLchar*)parg);
		break;
	case glfnGetAttachedShaders:
		glGetAttachedShaders((GLuint)args->a0, (GLsizei)args->a1, (GLsizei*)&ret, (GLuint*)parg);
		break;
	case glfnGetAttribLocation:
		ret = glGetAttribLocation((GLint)args->a0, (GLchar*)args->a1);
		break;
	case glfnGetBooleanv:
		glGetBooleanv((GLenum)args->a0, (GLboolean*)parg);
		break;
	case glfnGetBufferParameteri:
		glGetBufferParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)&ret);
		break;
	case glfnGetFloatv:
		glGetFloatv((GLenum)args->a0, (GLfloat*)parg);
		break;
	case glfnGetIntegerv:
		glGetIntegerv((GLenum)args->a0, (GLint*)parg);
		break;
	case glfnGetError:
		ret = glGetError();
		break;
	case glfnGetFramebufferAttachmentParameteriv:
		glGetFramebufferAttachmentParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint*)&ret);
		break;
	case glfnGetProgramiv:
		glGetProgramiv((GLint)args->a0, (GLenum)args->a1, (GLint*)&ret);
		break;
	case glfnGetProgramInfoLog:
		glGetProgramInfoLog((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg);
		break;
	case glfnGetRenderbufferParameteriv:
		glGetRenderbufferParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)&ret);
		break;
	case glfnGetShaderiv:
		glGetShaderiv((GLint)args->a0, (GLenum)args->a1, (GLint*)&ret);
		break;
	case glfnGetShaderInfoLog:
		glGetShaderInfoLog((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg);
		break;
	case glfnGetShaderPrecisionFormat:
		glGetShaderPrecisionFormat((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg, &((GLint*)parg)[2]);
		break;
	case glfnGetShaderSource:
		glGetShaderSource((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg);
		break;
	case glfnGetString:
		ret = (uintptr_t)glGetString((GLenum)args->a0);
		break;
	case glfnGetTexParameterfv:
		glGetTexParameterfv((GLenum)args->a0, (GLenum)args->a1, (GLfloat*)parg);
		break;
	case glfnGetTexParameteriv:
		glGetTexParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg);
		break;
	case glfnGetUniformfv:
		glGetUniformfv((GLuint)args->a0, (GLint)args->a1, (GLfloat*)parg);
		break;
	case glfnGetUniformiv:
		glGetUniformiv((GLuint)args->a0, (GLint)args->a1, (GLint*)parg);
		break;
	case glfnGetUniformLocation:
		ret = glGetUniformLocation((GLint)args->a0, (GLchar*)args->a1);
		break;
	case glfnGetVertexAttribfv:
		glGetVertexAttribfv((GLuint)args->a0, (GLenum)args->a1, (GLfloat*)parg);
		break;
	case glfnGetVertexAttribiv:
		glGetVertexAttribiv((GLuint)args->a0, (GLenum)args->a1, (GLint*)parg);
		break;
	case glfnHint:
		glHint((GLenum)args->a0, (GLenum)args->a1);
		break;
	case glfnIsBuffer:
		ret = glIsBuffer((GLint)args->a0);
		break;
	case glfnIsEnabled:
		ret = glIsEnabled((GLenum)args->a0);
		break;
	case glfnIsFramebuffer:
		ret = glIsFramebuffer((GLint)args->a0);
		break;
	case glfnIsProgram:
		ret = glIsProgram((GLint)args->a0);
		break;
	case glfnIsRenderbuffer:
		ret = glIsRenderbuffer((GLint)args->a0);
		break;
	case glfnIsShader:
		ret = glIsShader((GLint)args->a0);
		break;
	case glfnIsTexture:
		ret = glIsTexture((GLint)args->a0);
		break;
	case glfnLineWidth:
		glLineWidth(*(GLfloat*)&args->a0);
		break;
	case glfnLinkProgram:
		glLinkProgram((GLint)args->a0);
		break;
	case glfnPixelStorei:
		glPixelStorei((GLenum)args->a0, (GLint)args->a1);
		break;
	case glfnPolygonOffset:
		glPolygonOffset(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1);
		break;
	case glfnReadPixels:
		glReadPixels((GLint)args->a0, (GLint)args->a1, (GLsizei)args->a2, (GLsizei)args->a3, (GLenum)args->a4, (GLenum)args->a5, (void*)parg);
		break;
	case glfnReleaseShaderCompiler:
		glReleaseShaderCompiler();
		break;
	case glfnRenderbufferStorage:
		glRenderbufferStorage((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2, (GLint)args->a3);
		break;
	case glfnSampleCoverage:
		glSampleCoverage(*(GLfloat*)&args->a0, (GLboolean)args->a1);
		break;
	case glfnScissor:
		glScissor((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3);
		break;
	case glfnShaderSource:
#if defined(os_ios) || defined(os_osx)
		glShaderSource((GLuint)args->a0, (GLsizei)args->a1, (const GLchar *const *)args->a2, NULL);
#else
		glShaderSource((GLuint)args->a0, (GLsizei)args->a1, (const GLchar **)args->a2, NULL);
#endif
		break;
	case glfnStencilFunc:
		glStencilFunc((GLenum)args->a0, (GLint)args->a1, (GLuint)args->a2);
		break;
	case glfnStencilFuncSeparate:
		glStencilFuncSeparate((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2, (GLuint)args->a3);
		break;
	case glfnStencilMask:
		glStencilMask((GLuint)args->a0);
		break;
	case glfnStencilMaskSeparate:
		glStencilMaskSeparate((GLenum)args->a0, (GLuint)args->a1);
		break;
	case glfnStencilOp:
		glStencilOp((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2);
		break;
	case glfnStencilOpSeparate:
		glStencilOpSeparate((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLenum)args->a3);
		break;
	case glfnTexImage2D:
		glTexImage2D(
			(GLenum)args->a0,
			(GLint)args->a1,
			(GLint)args->a2,
			(GLsizei)args->a3,
			(GLsizei)args->a4,
			0, // border
			(GLenum)args->a5,
			(GLenum)args->a6,
			(const GLvoid*)parg);
		break;
	case glfnTexSubImage2D:
		glTexSubImage2D(
			(GLenum)args->a0,
			(GLint)args->a1,
			(GLint)args->a2,
			(GLint)args->a3,
			(GLsizei)args->a4,
			(GLsizei)args->a5,
			(GLenum)args->a6,
			(GLenum)args->a7,
			(const GLvoid*)parg);
		break;
	case glfnTexParameterf:
		glTexParameterf((GLenum)args->a0, (GLenum)args->a1, *(GLfloat*)&args->a2);
		break;
	case glfnTexParameterfv:
		glTexParameterfv((GLenum)args->a0, (GLenum)args->a1, (GLfloat*)parg);
		break;
	case glfnTexParameteri:
		glTexParameteri((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2);
		break;
	case glfnTexParameteriv:
		glTexParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg);
		break;
	case glfnUniform1f:
		glUniform1f((GLint)args->a0, *(GLfloat*)&args->a1);
		break;
	case glfnUniform1fv:
		glUniform1fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg);
		break;
	case glfnUniform1i:
		glUniform1i((GLint)args->a0, (GLint)args->a1);
		break;
	case glfnUniform1iv:
		glUniform1iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg);
		break;
	case glfnUniform2f:
		glUniform2f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2);
		break;
	case glfnUniform2fv:
		glUniform2fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg);
		break;
	case glfnUniform2i:
		glUniform2i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2);
		break;
	case glfnUniform2iv:
		glUniform2iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg);
		break;
	case glfnUniform3f:
		glUniform3f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3);
		break;
	case glfnUniform3fv:
		glUniform3fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg);
		break;
	case glfnUniform3i:
		glUniform3i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3);
		break;
	case glfnUniform3iv:
		glUniform3iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg);
		break;
	case glfnUniform4f:
		glUniform4f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3, *(GLfloat*)&args->a4);
		break;
	case glfnUniform4fv:
		glUniform4fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg);
		break;
	case glfnUniform4i:
		glUniform4i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4);
		break;
	case glfnUniform4iv:
		glUniform4iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg);
		break;
	case glfnUniformMatrix2fv:
		glUniformMatrix2fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg);
		break;
	case glfnUniformMatrix3fv:
		glUniformMatrix3fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg);
		break;
	case glfnUniformMatrix4fv:
		glUniformMatrix4fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg);
		break;
	case glfnUseProgram:
		glUseProgram((GLint)args->a0);
		break;
	case glfnValidateProgram:
		glValidateProgram((GLint)args->a0);
		break;
	case glfnVertexAttrib1f:
		glVertexAttrib1f((GLint)args->a0, *(GLfloat*)&args->a1);
		break;
	case glfnVertexAttrib1fv:
		glVertexAttrib1fv((GLint)args->a0, (GLfloat*)parg);
		break;
	case glfnVertexAttrib2f:
		glVertexAttrib2f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2);
		break;
	case glfnVertexAttrib2fv:
		glVertexAttrib2fv((GLint)args->a0, (GLfloat*)parg);
		break;
	case glfnVertexAttrib3f:
		glVertexAttrib3f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3);
		break;
	case glfnVertexAttrib3fv:
		glVertexAttrib3fv((GLint)args->a0, (GLfloat*)parg);
		break;
	case glfnVertexAttrib4f:
		glVertexAttrib4f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3, *(GLfloat*)&args->a4);
		break;
	case glfnVertexAttrib4fv:
		glVertexAttrib4fv((GLint)args->a0, (GLfloat*)parg);
		break;
	case glfnVertexAttribPointer:
		glVertexAttribPointer((GLuint)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLboolean)args->a3, (GLsizei)args->a4, (const GLvoid*)args->a5);
		break;
	case glfnViewport:
		glViewport((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3);
		break;
	}
	return ret;
}
Esempio n. 20
0
void Scene::splatRecords()
{
  /*irradianceRecord rec1, rec2, rec3;
  rec1.pos[0] = 2.1766;
  rec1.pos[1] = 1.8176;
  rec1.pos[2] = 5.1762;
  rec1.norm[0] = -.573576;
  rec1.norm[1] = 0;
  rec1.norm[2] = -.819152;
  rec1.irradiance[0] = 1;
  rec1.irradiance[1] = 0;
  rec1.irradiance[2] = 0;
  rec1.hmd = 1.0;

  records.clear();
  records.push_back(rec1);
  */
  float eye[3];
  float eyedir[3];
  float up[3] = {0.0, 1.0, 0.0};
  view->getEye(eye);
  view->getCenter(eyedir);

  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, splatBufFBOID);
  glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
  glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
  glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
			    GL_TEXTURE_2D, splatTex, 0);
  glViewport(0, 0, windWidth, windHeight);
  glEnable(GL_BLEND);
  glBlendFunc(GL_ONE, GL_ONE);//add all the contributions together
  
  glUseProgram(splatProgram);
  glClear(GL_COLOR_BUFFER_BIT);
  glDisable(GL_LIGHTING);
  glDisable(GL_DEPTH_TEST);
  viewProjSetup(eye, eyedir, up, 45.0, 1.0, defaultFront, defaultBack);

  float color[4] = {1, 0, 1, 1};
  glPointSize(5);
  glColor4fv(color);

  //set up samplers
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, coordTexBase[0]);
  glActiveTexture(GL_TEXTURE1);
  glBindTexture(GL_TEXTURE_2D, coordTexBase[1]);
  glActiveTexture(GL_TEXTURE2);
  glBindTexture(GL_TEXTURE_2D, coordTexBase[2]);
  
  float ws[2] = {windWidth, windHeight};
  std::cout << splatWindSizeUniform << std::endl;
  glUniform2fv(splatWindSizeUniform, 1, ws);

  glUniform1f(splatAUniform, a);

  glUniform1i(splatWorldPosUniform, 0);
  glUniform1i(splatWorldNormUniform, 1);
  glUniform1i(splatDiffuseUniform, 2);

  for(size_t i = 0; i < records.size(); ++i)
    {
      glUniform1f(splatUniform,records[i].hmd*a);
      glUniform1f(splatHmdUniform, records[i].hmd);
      glBegin(GL_QUADS);
      for(int j = 0; j < 4; ++j)
	{
	  glVertexAttrib1f(splatAttribute, 3 - j);
	  glNormal3fv(records[i].norm);
	  glColor3fv(records[i].irradiance);
	  glVertex3fv(records[i].pos);
	}
      glEnd();
    }

  glFlush();
  //glutSwapBuffers();
  std::cout << records.size() << "records splatted" << std::endl;
  Helpers::getGLErrors("end of splat");
  glIsShader(999);
  glIsTexture(222);
  std::cout << "after first records splatted " << timer.split() << std::endl;
  //now do another frag shader pass
  
  //now read the buffer back and to the CPU traversal
  
  glBindTexture(GL_TEXTURE_2D, splatTex);
  glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, splatBuffer);

  int startNewRecords = records.size();
  float * newpos;
  float * newnorm;

  double modelviewmat[16];
  double projectionmat[16];
  glGetDoublev(GL_MODELVIEW_MATRIX, modelviewmat);
  matrix4x4 modmat(modelviewmat);
  glGetDoublev(GL_PROJECTION_MATRIX, projectionmat);
  matrix4x4 projmat(projectionmat);

  double identity[16] = { 1, 0, 0, 0,
			  0, 1, 0, 0,
			  0, 0, 1, 0,
			  0, 0, 0, 1};

  vector3d xyz, norm, eyeCoord, perpLeft, perpDown;
  float upv[3] = {0, 1, 0}, right[3] = {1, 0, 0};
  vector3d upvec(upv);
  vector3d rightvec(right);

  vector3d botleft, topright;
  vector3d projbotLeft, projtopRight;

  float hmd;

  double x1, y1, z1, x2, y2, z2;//for gluproject

  GLint vp[4] = {0, 0, windWidth, windHeight};

  int xmin, xmax, ymin, ymax;

  for(size_t y = 0; y < windHeight; ++y)
    {
      for(size_t x = 0; x < windWidth; ++x)
	{
	  if(splatBuffer[(y*windWidth +x)*4 + 3] < a)
	    {
	      newpos = &objectCoords[(y*windWidth +x)*3];
	      newnorm = &objectNormals[(y*windWidth +x)*3];
	      generateRecord(newpos, newnorm);

	      hmd = records.back().hmd;

	      //do a simple cpusplat to update nearby weights
	      //mimic the v and f shaders almost exactly
	      xyz = vector3d(newpos);
	      norm = vector3d(newnorm);

	      eyeCoord = modmat.mult(xyz);
	      
	      perpLeft = (((eyeCoord.normalize()).cross(upvec)).normalize()).scale(a*hmd);
	      perpDown = (((eyeCoord.normalize()).cross(rightvec)).normalize()).scale(a*hmd);
	      

	      botleft = eyeCoord + perpLeft + perpDown;
	      topright = eyeCoord - perpLeft - perpDown;
	      
	      gluProject(botleft.xyz[0], botleft.xyz[1], botleft.xyz[2],
			 identity, projectionmat, vp,
			 &x1, &y1, &z1);

	      gluProject(topright.xyz[0], topright.xyz[1], topright.xyz[2],
			 identity, projectionmat, vp,
			 &x2, &y2, &z2);
	      
	      //bottom left is actually bottom right
	      // top right is actually top left
	      //WTF!!

	      xmin = std::max(0, int(x2));
	      xmax = std::min(int(windWidth), int(ceil(x1)));
	      ymin = std::max(0, int(y1));
	      ymax = std::min(int(windHeight), int(ceil(y2)));
	      //std::cout << "updating range: x1 x2, y1 y2: " << xmin <<
	      //' ' << xmax << ' ' << ymin << ' ' << ymax << std::endl;
	      //splat the w coord
	      int offset;
	      float w, dist, sqrtnrm, dot;
	      for(int fragy = ymin; fragy < ymax; ++fragy)
		{
		  for(int fragx = xmin; fragx < xmax; ++fragx)
		    {
		      //compute distance:
		      offset = (fragy*windWidth + fragx)*3;


		      dist = sqrt(pow(newpos[0] - objectCoords[offset], 2) +
				  pow(newpos[1] - objectCoords[offset+1],2)+
				  pow(newpos[2] - objectCoords[offset+2],2));
		      
		      if(dist >= a*hmd)
			continue;
		      dot = newnorm[0]*objectNormals[offset] +
			newnorm[1]*objectNormals[offset +1] +
			newnorm[2]*objectNormals[offset +2];
		      dot = std::min(1.0f, dot);
		      sqrtnrm = sqrt(1.0 - dot);

		      w = 1.0/((dist/hmd) + sqrtnrm);
		      if (w >= 1.0/a)
			{
			  splatBuffer[(fragy*windWidth +fragx)*4 + 3] += w;
			}
		      
		    }

		}

	    }
	}
    }
  std::cout << "cpu traversal" << timer.split() << std::endl;

  std::cout << "about to splat new records" << std::endl;
  glUseProgram(splatProgram);
  //splat the newly added records
  for(size_t i = startNewRecords; i < records.size(); ++i)
    {
      glUniform1f(splatUniform,records[i].hmd*a);
      glUniform1f(splatHmdUniform, records[i].hmd);
      glBegin(GL_QUADS);
      for(int j = 0; j < 4; ++j)
	{
	  glVertexAttrib1f(splatAttribute, 3 - j);
	  glNormal3fv(records[i].norm);
	  glColor3fv(records[i].irradiance);
	  glVertex3fv(records[i].pos);
	}
      glEnd();
    }
  std::cout << records.size() - startNewRecords << " new records created" <<
    std::endl;
  glFlush();


}
Esempio n. 21
0
void GlShaderProgram::setAttributeFloat(const std::string &variableName, const float f) {
  GLint loc = getAttributeVariableLocation(variableName);
  glVertexAttrib1f(loc, f);
}
Esempio n. 22
0
void ShaderProgram::sendVertexAttrib1f(GLint location, GLfloat v0)
{
	bind();
	glVertexAttrib1f(location, v0);
	unbind();
}
Esempio n. 23
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL20_nglVertexAttrib1f(JNIEnv *env, jclass clazz, jint index, jfloat x, jlong function_pointer) {
	glVertexAttrib1fPROC glVertexAttrib1f = (glVertexAttrib1fPROC)((intptr_t)function_pointer);
	glVertexAttrib1f(index, x);
}
Esempio n. 24
0
enum piglit_result piglit_display(void)
{
	GLvoid *datap;
	GLint intv[] = { 1, 1, 1, 1 };
	GLfloat floatv[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat quad[] = { -1.0, 1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0 };

	GLsizei length;
	GLint size;
	GLenum type;
	GLchar buffer[64];

	GLuint program, vShader, fShader;
	int maxAttribCount;

	/* --- valid program needed for some of the functions --- */

	fShader = glCreateShader(GL_FRAGMENT_SHADER);
	vShader = glCreateShader(GL_VERTEX_SHADER);

	glShaderSource(fShader, 1, &fShaderString, NULL);
	glShaderSource(vShader, 1, &vShaderString, NULL);

	glCompileShader(vShader);
	glCompileShader(fShader);

	program = glCreateProgram();

	glAttachShader(program, vShader);
	glAttachShader(program, fShader);

	glLinkProgram(program);

	glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttribCount);

	/* --- tests begin here --- */

	glVertexAttrib1f(maxAttribCount, floatv[0]);
	CHECK_GL_INVALID_VALUE;

	glVertexAttrib2f(maxAttribCount, floatv[0], floatv[1]);
	CHECK_GL_INVALID_VALUE;

	glVertexAttrib3f(maxAttribCount, floatv[0], floatv[1], floatv[2]);
	CHECK_GL_INVALID_VALUE;

	glVertexAttrib4f(maxAttribCount, floatv[0], floatv[1], floatv[2],
			 floatv[3]);
	CHECK_GL_INVALID_VALUE;

	glVertexAttrib1fv(maxAttribCount, floatv);
	CHECK_GL_INVALID_VALUE;

	glVertexAttrib2fv(maxAttribCount, floatv);
	CHECK_GL_INVALID_VALUE;

	glVertexAttrib3fv(maxAttribCount, floatv);
	CHECK_GL_INVALID_VALUE;

	glVertexAttrib4fv(maxAttribCount, floatv);
	CHECK_GL_INVALID_VALUE;

	glVertexAttribPointer(maxAttribCount, 2, GL_FLOAT, GL_FALSE, 0, quad);
	CHECK_GL_INVALID_VALUE;

	glBindAttribLocation(program, maxAttribCount, "pos");
	CHECK_GL_INVALID_VALUE;

	glEnableVertexAttribArray(maxAttribCount);
	CHECK_GL_INVALID_VALUE;

	glDisableVertexAttribArray(maxAttribCount);
	CHECK_GL_INVALID_VALUE;

	glGetVertexAttribfv(maxAttribCount, GL_CURRENT_VERTEX_ATTRIB, floatv);
	CHECK_GL_INVALID_VALUE;

	glGetVertexAttribiv(maxAttribCount, GL_CURRENT_VERTEX_ATTRIB, intv);
	CHECK_GL_INVALID_VALUE;

	glGetVertexAttribPointerv(maxAttribCount, GL_VERTEX_ATTRIB_ARRAY_POINTER, &datap);
	CHECK_GL_INVALID_VALUE;

	glGetActiveAttrib(program, maxAttribCount, 64, &length, &size, &type, buffer);
	CHECK_GL_INVALID_VALUE;

	return PIGLIT_PASS;
}
Esempio n. 25
0
	bool ShaderManager :: SetAttributeFloat ( int location, float value )
	{
		glVertexAttrib1f ( location, value );

		return true;
	}
Esempio n. 26
0
// 1{f,d,s,fv,dv,sv}
void shader_gl3::attribute(const char* name, const float& arg1) const {
	A2E_CHECK_ATTRIBUTE_EXISTENCE(name);
	A2E_CHECK_ATTRIBUTE_TYPE(name, GL_FLOAT);
	glVertexAttrib1f(A2E_SHADER_GET_ATTRIBUTE_POSITION(name), arg1);
}
Esempio n. 27
0
 void vertex_attrib_1f(gl::uint_t index, gl::float_t x) {
   glVertexAttrib1f(index, x);
 }
Esempio n. 28
0
//==========================================================================
//
//
//
//==========================================================================
void GLWall::DrawDecal(DBaseDecal *decal)
{
	line_t * line=seg->linedef;
	side_t * side=seg->sidedef;
	int i;
	fixed_t zpos;
	int light;
	int rel;
	float a;
	bool flipx, flipy, loadAlpha;
	DecalVertex dv[4];
	FTextureID decalTile;
	

	if (decal->RenderFlags & RF_INVISIBLE) return;
	if (type==RENDERWALL_FFBLOCK && gltexture->isMasked()) return;	// No decals on 3D floors with transparent textures.

	//if (decal->sprite != 0xffff)
	{
		decalTile = decal->PicNum;
		flipx = !!(decal->RenderFlags & RF_XFLIP);
		flipy = !!(decal->RenderFlags & RF_YFLIP);
	}
	/*
	else
	{
	decalTile = SpriteFrames[sprites[decal->sprite].spriteframes + decal->frame].lump[0];
	flipx = SpriteFrames[sprites[decal->sprite].spriteframes + decal->frame].flip & 1;
	}
	*/

	FTexture *texture = TexMan[decalTile];
	if (texture == NULL) return;

	FMaterial *tex;


	if (texture->UseType == FTexture::TEX_MiscPatch)
	{
		// We need to create a clone of this texture where we can force the
		// texture filtering offset in.
		if (texture->gl_info.DecalTexture == NULL)
		{
			texture->gl_info.DecalTexture = new FCloneTexture(texture, FTexture::TEX_Decal);
		}
		tex = FMaterial::ValidateTexture(texture->gl_info.DecalTexture);
	}
	else tex = FMaterial::ValidateTexture(texture);


	// the sectors are only used for their texture origin coordinates
	// so we don't need the fake sectors for deep water etc.
	// As this is a completely split wall fragment no further splits are
	// necessary for the decal.
	sector_t *frontsector;

	// for 3d-floor segments use the model sector as reference
	if ((decal->RenderFlags&RF_CLIPMASK)==RF_CLIPMID) frontsector=decal->Sector;
	else frontsector=seg->frontsector;

	switch (decal->RenderFlags & RF_RELMASK)
	{
	default:
		// No valid decal can have this type. If one is encountered anyway
		// it is in some way invalid so skip it.
		return;
		//zpos = decal->z;
		//break;

	case RF_RELUPPER:
		if (type!=RENDERWALL_TOP) return;
		if (line->flags & ML_DONTPEGTOP)
		{
			zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::ceiling);
		}
		else
		{
			zpos = decal->Z + seg->backsector->GetPlaneTexZ(sector_t::ceiling);
		}
		break;
	case RF_RELLOWER:
		if (type!=RENDERWALL_BOTTOM) return;
		if (line->flags & ML_DONTPEGBOTTOM)
		{
			zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::ceiling);
		}
		else
		{
			zpos = decal->Z + seg->backsector->GetPlaneTexZ(sector_t::floor);
		}
		break;
	case RF_RELMID:
		if (type==RENDERWALL_TOP || type==RENDERWALL_BOTTOM) return;
		if (line->flags & ML_DONTPEGBOTTOM)
		{
			zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::floor);
		}
		else
		{
			zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::ceiling);
		}
	}
	
	if (decal->RenderFlags & RF_FULLBRIGHT)
	{
		light = 255;
		rel = 0;
	}
	else
	{
		light = lightlevel;
		rel = rellight + getExtraLight();
	}
	
	int r = RPART(decal->AlphaColor);
	int g = GPART(decal->AlphaColor);
	int b = BPART(decal->AlphaColor);
	FColormap p = Colormap;
	
	if (glset.nocoloredspritelighting)
	{
		int v = (Colormap.LightColor.r * 77 + Colormap.LightColor.g*143 + Colormap.LightColor.b*35)/255;
		p.LightColor = PalEntry(p.colormap, v, v, v);
	}
	
	float red, green, blue;
	
	if (decal->RenderStyle.Flags & STYLEF_RedIsAlpha)
	{
		loadAlpha = true;
		p.colormap=CM_SHADE;

		if (glset.lightmode != 8)
		{
			gl_GetLightColor(light, rel, &p, &red, &green, &blue);
		}
		else
		{
			gl_GetLightColor(lightlevel, rellight, &p, &red, &green, &blue);
		}
		
		if (gl_lights && GLRenderer->mLightCount && !gl_fixedcolormap && gl_light_sprites)
		{
			float result[3];
			fixed_t x, y;
			decal->GetXY(seg->sidedef, x, y);
			gl_GetSpriteLight(NULL, x, y, zpos, sub, Colormap.colormap-CM_DESAT0, result, line, side == line->sidedef[0]? 0:1);
			if (glset.lightmode != 8)
			{
				red = clamp<float>(result[0]+red, 0, 1.0f);
				green = clamp<float>(result[1]+green, 0, 1.0f);
				blue = clamp<float>(result[2]+blue, 0, 1.0f);
			}
			else
			{
				gl_RenderState.SetDynLight(result[0], result[1], result[2]);
			}
		}

		BYTE R = xs_RoundToInt(r * red);
		BYTE G = xs_RoundToInt(g * green);
		BYTE B = xs_RoundToInt(b * blue);

		gl_ModifyColor(R,G,B, Colormap.colormap);

		red = R/255.f;
		green = G/255.f;
		blue = B/255.f;
	}	
	else
	{
		loadAlpha = false;
		
		red = 1.f;
		green = 1.f;
		blue = 1.f;
	}
	
	
	a = FIXED2FLOAT(decal->Alpha);
	
	// now clip the decal to the actual polygon
	float decalwidth = tex->TextureWidth(GLUSE_PATCH)  * FIXED2FLOAT(decal->ScaleX);
	float decalheight= tex->TextureHeight(GLUSE_PATCH) * FIXED2FLOAT(decal->ScaleY);
	float decallefto = tex->GetLeftOffset(GLUSE_PATCH) * FIXED2FLOAT(decal->ScaleX);
	float decaltopo  = tex->GetTopOffset(GLUSE_PATCH)  * FIXED2FLOAT(decal->ScaleY);

	
	float leftedge = glseg.fracleft * side->TexelLength;
	float linelength = glseg.fracright * side->TexelLength - leftedge;

	// texel index of the decal's left edge
	float decalpixpos = (float)side->TexelLength * decal->LeftDistance / (1<<30) - (flipx? decalwidth-decallefto : decallefto) - leftedge;

	float left,right;
	float lefttex,righttex;

	// decal is off the left edge
	if (decalpixpos < 0)
	{
		left = 0;
		lefttex = -decalpixpos;
	}
	else
	{
		left = decalpixpos;
		lefttex = 0;
	}
	
	// decal is off the right edge
	if (decalpixpos + decalwidth > linelength)
	{
		right = linelength;
		righttex = right - decalpixpos;
	}
	else
	{
		right = decalpixpos + decalwidth;
		righttex = decalwidth;
	}
	if (right<=left) return;	// nothing to draw

	// one texture unit on the wall as vector
	float vx=(glseg.x2-glseg.x1)/linelength;
	float vy=(glseg.y2-glseg.y1)/linelength;
		
	dv[1].x=dv[0].x=glseg.x1+vx*left;
	dv[1].y=dv[0].y=glseg.y1+vy*left;

	dv[3].x=dv[2].x=glseg.x1+vx*right;
	dv[3].y=dv[2].y=glseg.y1+vy*right;
		
	zpos+= FRACUNIT*(flipy? decalheight-decaltopo : decaltopo);

	tex->BindPatch(p.colormap, decal->Translation);

	dv[1].z=dv[2].z = FIXED2FLOAT(zpos);
	dv[0].z=dv[3].z = dv[1].z - decalheight;
	dv[1].v=dv[2].v = tex->GetVT();

	dv[1].u=dv[0].u = tex->GetU(lefttex / FIXED2FLOAT(decal->ScaleX));
	dv[3].u=dv[2].u = tex->GetU(righttex / FIXED2FLOAT(decal->ScaleX));
	dv[0].v=dv[3].v = tex->GetVB();


	// now clip to the top plane
	float vzt=(ztop[1]-ztop[0])/linelength;
	float topleft=this->ztop[0]+vzt*left;
	float topright=this->ztop[0]+vzt*right;

	// completely below the wall
	if (topleft<dv[0].z && topright<dv[3].z) 
		return;

	if (topleft<dv[1].z || topright<dv[2].z)
	{
		// decal has to be clipped at the top
		// let texture clamping handle all extreme cases
		dv[1].v=(dv[1].z-topleft)/(dv[1].z-dv[0].z)*dv[0].v;
		dv[2].v=(dv[2].z-topright)/(dv[2].z-dv[3].z)*dv[3].v;
		dv[1].z=topleft;
		dv[2].z=topright;
	}

	// now clip to the bottom plane
	float vzb=(zbottom[1]-zbottom[0])/linelength;
	float bottomleft=this->zbottom[0]+vzb*left;
	float bottomright=this->zbottom[0]+vzb*right;

	// completely above the wall
	if (bottomleft>dv[1].z && bottomright>dv[2].z) 
		return;

	if (bottomleft>dv[0].z || bottomright>dv[3].z)
	{
		// decal has to be clipped at the bottom
		// let texture clamping handle all extreme cases
		dv[0].v=(dv[1].z-bottomleft)/(dv[1].z-dv[0].z)*(dv[0].v-dv[1].v) + dv[1].v;
		dv[3].v=(dv[2].z-bottomright)/(dv[2].z-dv[3].z)*(dv[3].v-dv[2].v) + dv[2].v;
		dv[0].z=bottomleft;
		dv[3].z=bottomright;
	}


	if (flipx)
	{
		float ur = tex->GetUR();
		for(i=0;i<4;i++) dv[i].u=ur-dv[i].u;
	}
	if (flipy)
	{
		float vb = tex->GetVB();
		for(i=0;i<4;i++) dv[i].v=vb-dv[i].v;
	}
	// fog is set once per wall in the calling function and not per decal!

	if (loadAlpha)
	{
		glColor4f(red, green, blue, a);

		if (glset.lightmode == 8)
		{
			if (gl_fixedcolormap)
				glVertexAttrib1f(VATTR_LIGHTLEVEL, 1.0);
			else
				glVertexAttrib1f(VATTR_LIGHTLEVEL, gl_CalcLightLevel(light, rel, false) / 255.0);
		}
	}
	else
	{
		if (glset.lightmode == 8)
		{
			gl_SetColor(light, rel, &p, a, extralight); // Korshun.
		}
		else
		{
			gl_SetColor(light, rel, &p, a);
		}
	}

	PalEntry fc = gl_RenderState.GetFogColor();
	if (decal->RenderStyle.BlendOp == STYLEOP_Add && decal->RenderStyle.DestAlpha == STYLEALPHA_One)
	{
		gl_RenderState.SetFog(0,-1);
	}


	gl_SetRenderStyle(decal->RenderStyle, false, false);

	// If srcalpha is one it looks better with a higher alpha threshold
	if (decal->RenderStyle.SrcAlpha == STYLEALPHA_One) gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold);
	else gl_RenderState.AlphaFunc(GL_GREATER, 0.f);

	gl_RenderState.Apply();
	glBegin(GL_TRIANGLE_FAN);
	for(i=0;i<4;i++)
	{
		glTexCoord2f(dv[i].u,dv[i].v);
		glVertex3f(dv[i].x,dv[i].z,dv[i].y);
	}
	glEnd();
	rendered_decals++;
	gl_RenderState.SetFog(fc,-1);
	gl_RenderState.SetDynLight(0,0,0);
}
Esempio n. 29
0
// Draw a cylinder with supplied dimensions
void DrawCylinder(GLfloat length, GLfloat diameter1, GLfloat diameter2, 
                  GLfloat startWeight, GLfloat endWeight)
{
    int numFacets = 50;
    int numSections = 50;
    GLfloat angleIncr = (2.0f * 3.14159f) / (float)numFacets;
    GLfloat sectionLength = length / numSections;
    GLfloat wEnd, influenceStart;
    int i, j;

    // Determine where our influence starts for this limb
    if (startWeight == 0.5f)
    {
        influenceStart = sphereOfInfluence;
    }
    else
    {
        influenceStart = 1.0f - sphereOfInfluence;
    }

    // Skin
    for (i = 0; i < numFacets; i++)
    {
        // Calculate geometry for this facet
        GLfloat angle1 = i * angleIncr;
        GLfloat angle2 = ((i+1)%numFacets) * angleIncr;
        GLfloat y1AtFirstEnd = sin(angle1) * diameter1;
        GLfloat y1AtOtherEnd = sin(angle1) * diameter2;
        GLfloat z1AtFirstEnd = cos(angle1) * diameter1;
        GLfloat z1AtOtherEnd = cos(angle1) * diameter2;
        GLfloat y2AtFirstEnd = sin(angle2) * diameter1;
        GLfloat y2AtOtherEnd = sin(angle2) * diameter2;
        GLfloat z2AtFirstEnd = cos(angle2) * diameter1;
        GLfloat z2AtOtherEnd = cos(angle2) * diameter2;
        GLfloat n1y = y1AtFirstEnd;
        GLfloat n1z = z1AtFirstEnd;
        GLfloat n2y = y2AtFirstEnd;
        GLfloat n2z = z2AtFirstEnd;

        // One strip per facet
        glBegin(GL_QUAD_STRIP);

        glVertexAttrib1f(weightLoc, useBlending ? startWeight : 1.0f);
        glNormal3f(0.0f, n1y, n1z);
        glVertex3f(0.0f, y1AtFirstEnd, z1AtFirstEnd);
        glNormal3f(0.0f, n2y, n2z);
        glVertex3f(0.0f, y2AtFirstEnd, z2AtFirstEnd);

        for (j = 0; j < numSections; j++)
        {
            // Calculate geometry for end of this quad
            GLfloat paramEnd = (float)(j+1) / (float)numSections;
            GLfloat lengthEnd = paramEnd * length;
            GLfloat y1End = y1AtFirstEnd + (paramEnd * (y1AtOtherEnd - y1AtFirstEnd));
            GLfloat z1End = z1AtFirstEnd + (paramEnd * (z1AtOtherEnd - z1AtFirstEnd));
            GLfloat y2End = y2AtFirstEnd + (paramEnd * (y2AtOtherEnd - y2AtFirstEnd));
            GLfloat z2End = z2AtFirstEnd + (paramEnd * (z2AtOtherEnd - z2AtFirstEnd));

            // Calculate vertex weights
            if (!useBlending)
            {
                wEnd = 1.0f;
            }
            else if (paramEnd <= influenceStart)
            {
                // Map params [0,influenceStart] to weights [0,1]
                GLfloat p = (paramEnd * (1.0f/influenceStart));

                // We're in the first half of the cylinder: startWeight -> 1
                wEnd = startWeight + p * (1.0f - startWeight);
            }
            else
            {
                // Map params [influenceStart,1] to weights [0,1]
                GLfloat p = (paramEnd-influenceStart) * (1.0f/(1.0f-influenceStart));

                // We're in the second half of the cylinder: 1 -> endWeight
                wEnd = 1.0f + p * (endWeight - 1.0f);
            }

            glVertexAttrib1f(weightLoc, wEnd);
            glNormal3f(0.0f, n1y, n1z);
            glVertex3f(lengthEnd, y1End, z1End);
            glNormal3f(0.0f, n2y, n2z);
            glVertex3f(lengthEnd, y2End, z2End);
        }

        // End facet strip
        glEnd();
    }

    if (showBones)
    {
        // Skeleton
        glDisable(GL_DEPTH_TEST);
        glEnable(GL_BLEND);
        glColor4f(1.0f, 1.0f, 1.0f, 0.75f);
        glNormal3f(0.0f, 1.0f, 0.0f);
        glVertexAttrib1f(weightLoc, 1.0f);
        glBegin(GL_LINES);
            glVertex3f(0.0f, 0.0f, 0.0f);
            glVertex3f(length, 0.0f, 0.0f);
        glEnd();
        glColor3f(1.0f, 1.0f, 0.0f);
        glBegin(GL_POINTS);
            glVertex3f(0.0f, 0.0f, 0.0f);
            glVertex3f(length, 0.0f, 0.0f);
        glEnd();
        glEnable(GL_DEPTH_TEST);
        glDisable(GL_BLEND);
    }
}
    void Polygon::Draw()
    {
        //Safety check the shader
        if(m_Shader == nullptr)
        {
            return;
        }
        
        //If the model matrix is dirty, reset it
        if(IsModelMatrixDirty() == true)
        {
            ResetModelMatrix();
        }
    
        //Use the shader
        m_Shader->Use();
        
        //Set the point size attribute
        int pointSizeIndex = m_Shader->GetAttribute("a_pointSize");
        glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
        glVertexAttrib1f(pointSizeIndex, m_PointSize);
        
        //Cache the graphics service
        Graphics* graphics = ServiceLocator::GetGraphics();
    
        //Bind the vertex array object
        graphics->BindVertexArray(m_VertexArrayObject);

        //Set the model view projection matrix
        mat4 mvp = graphics->GetProjectionMatrix() * graphics->GetViewMatrix() * m_ModelMatrix;
        glUniformMatrix4fv(m_Shader->GetModelViewProjectionUniform(), 1, 0, &mvp[0][0]);
        
        //Validate the shader
        if(m_Shader->Validate() == false)
        {
            Error(false, "Can't draw Polygon, shader failed to validate");
            return;
        }
        
        //Disable blending, if we did in fact have it enabled
        if(m_Color.Alpha() != 1.0f)
        {
            graphics->EnableBlending();
        }
        
        //Render the polygon
        glDrawArrays(m_RenderMode, 0, (GLsizei)m_Vertices.size());
        
        //Disable blending, if we did in fact have it enabled
        if(m_Color.Alpha() != 1.0f)
        {
            graphics->DisableBlending();
        }
        
        //Unbind the vertex array
        ServiceLocator::GetGraphics()->BindVertexArray(0);
        
        //Draw the debug anchor point
        #if DRAW_POLYGON_ANCHOR_POINT
        if(GetType() != "Point" && GetType() != "Line")
        {
            Line lineA(m_AnchorLocation, vec2(m_AnchorLocation.x, m_AnchorLocation.y + DRAW_POLYGON_ANCHOR_POINT_SIZE));
            lineA.SetLocalAngle(GetWorldAngle());
            lineA.SetColor(Color::RedColor());
            lineA.Draw();
        
            Line lineB(m_AnchorLocation, vec2(m_AnchorLocation.x + DRAW_POLYGON_ANCHOR_POINT_SIZE, m_AnchorLocation.y));
            lineB.SetLocalAngle(GetWorldAngle());
            lineB.SetColor(Color::GreenColor());
            lineB.Draw();
        }
        #endif
        
        //Call the GameObject's Draw() method, this will ensure that any children will also get drawn
        GameObject::Draw();
    }