Beispiel #1
0
void AddFaceWithTextureScaled(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t vc,
                              const char* texture, bool bVertScale, bool bHorScale,
                              float minX, float minY, float maxX, float maxY)
{
    qtexture_t* pqtTexInfo;

    // TTimo: there used to be a call to pfnHasShader here
    //   this was not necessary. In Radiant everything is shader.
    //   If a texture doesn't have a shader script, a default shader object is used.
    // The IShader object was leaking also
    // collect texture info: sizes, etc
    IShader* i = QERApp_Shader_ForName(texture);
    pqtTexInfo = i->getTexture();	// shader width/height doesn't come out properly

    if(pqtTexInfo)
    {
        float scale[2] = {0.5f, 0.5f};
        float shift[2] = {0, 0};

        if(bHorScale)
        {
            int texWidth = pqtTexInfo->width;
            float width = maxX - minX;

            scale[0] = width/texWidth;
            shift[0] = -(float)((int)maxX%(int)width)/scale[0];
        }

        if(bVertScale)
        {
            int texHeight = pqtTexInfo->height;
            float height = maxY - minY;

            scale[1] = height/texHeight;
            shift[1] = (float)((int)minY%(int)height)/scale[1];
        }

        _QERFaceData addFace;
        FillDefaultTexture(&addFace, va, vb, vc, texture);
        addFace.m_texdef.scale[0] = scale[0];
        addFace.m_texdef.scale[1] = scale[1];
        addFace.m_texdef.shift[0] = shift[0];
        addFace.m_texdef.shift[1] = shift[1];

#if 0
        brush->m_brush->addPlane(addFace.m_p0, addFace.m_p1, addFace.m_p2, addFace.m_texdef);
#endif
    }
    else
    {
        // shouldn't even get here, as default missing texture should be returned if
        // texture doesn't exist, but just in case
        AddFaceWithTexture(brush, va, vb, vc, texture, FALSE);
        Sys_ERROR("BobToolz::Invalid Texture Name-> %s", texture);
    }
    // the IShader is not kept referenced, DecRef it
    i->DecRef();
}
Beispiel #2
0
void AddFaceWithTextureScaled(scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc, 
							  const char* texture, bool bVertScale, bool bHorScale, 
							  float minX, float minY, float maxX, float maxY)
{
	qtexture_t* pqtTexInfo;

  // TTimo: there used to be a call to pfnHasShader here
  //   this was not necessary. In Radiant everything is shader.
  //   If a texture doesn't have a shader script, a default shader object is used.
  // The IShader object was leaking also
	// collect texture info: sizes, etc
	IShader* i = GlobalShaderSystem().getShaderForName(texture);
  pqtTexInfo = i->getTexture();	// shader width/height doesn't come out properly

	if(pqtTexInfo)
	{
		float scale[2] = {0.5f, 0.5f};
		float shift[2] = {0, 0};

		if(bHorScale)
		{
			float width = maxX - minX;

			scale[0] = width/pqtTexInfo->width;
			shift[0] = -(float)((int)maxX%(int)width)/scale[0];
		}

		if(bVertScale)
		{
			float height = maxY - minY;

			scale[1] = height/pqtTexInfo->height;
			shift[1] = (float)((int)minY%(int)height)/scale[1];
		}

		_QERFaceData addFace;
		FillDefaultTexture(&addFace, va, vb, vc, texture);
		addFace.m_texdef.scale[0] = scale[0];
		addFace.m_texdef.scale[1] = scale[1];
		addFace.m_texdef.shift[0] = shift[0];
		addFace.m_texdef.shift[1] = shift[1];

    GlobalBrushCreator().Brush_addFace(brush, addFace);
	}
	else
	{
		// shouldn't even get here, as default missing texture should be returned if
		// texture doesn't exist, but just in case
		AddFaceWithTexture(brush, va, vb, vc, texture, false);
		globalErrorStream() << "BobToolz::Invalid Texture Name-> " << texture;
	}
  // the IShader is not kept referenced, DecRef it
  i->DecRef();
}
Beispiel #3
0
	// GTK CALLBACKS
	void TexturePreviewCombo::_onExpose (GtkWidget* widget, GdkEventExpose* ev, TexturePreviewCombo* self)
	{
		// Grab the GLWidget with sentry
		gtkutil::GLWidgetSentry sentry(widget);

		// Initialise viewport
		glClearColor(0.3, 0.3, 0.3, 0);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glDisable( GL_DEPTH_TEST);
		glEnable( GL_TEXTURE_2D);

		// If no texture is loaded, leave window blank
		if (self->_texName.empty())
			return;

		glMatrixMode( GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0, 1, 0, 1, -1, 1);

		// Get a reference to the selected shader
		IShader* shader = GlobalShaderSystem().getShaderForName(self->_texName);

		// Bind the texture from the shader
		GLTexture* tex = shader->getTexture();
		glBindTexture(GL_TEXTURE_2D, tex->texture_number);

		// Calculate the correct aspect ratio for preview
		float aspect = float(tex->width) / float(tex->height);
		float hfWidth, hfHeight;
		if (aspect > 1.0) {
			hfWidth = 0.5;
			hfHeight = 0.5 / aspect;
		} else {
			hfHeight = 0.5;
			hfWidth = 0.5 * aspect;
		}

		// Draw a polygon
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		glColor3f(1, 1, 1);
		glBegin( GL_QUADS);
		glTexCoord2i(0, 1);
		glVertex2f(0.5 - hfWidth, 0.5 - hfHeight);
		glTexCoord2i(1, 1);
		glVertex2f(0.5 + hfWidth, 0.5 - hfHeight);
		glTexCoord2i(1, 0);
		glVertex2f(0.5 + hfWidth, 0.5 + hfHeight);
		glTexCoord2i(0, 0);
		glVertex2f(0.5 - hfWidth, 0.5 + hfHeight);
		glEnd();

		shader->DecRef();
	}
Beispiel #4
0
void CShaderArray::ReleaseForShaderFile( const char *name ){
	int i;
	// decref
	for ( i = 0; i < CPtrArray::GetSize(); i++ )
	{
		IShader *pShader = static_cast < IShader * >( CPtrArray::GetAt( i ) );
		if ( !strcmp( name, pShader->getShaderFileName() ) ) {
			pShader->DecRef();
			CPtrArray::RemoveAt( i );
			i--;    // get ready for next loop
		}
	}
}
Beispiel #5
0
void ShaderChooser::shaderSelectionChanged(const std::string& shaderName, GtkListStore* listStore) {
	if (_targetEntry != NULL) {
		const char *value = shaderName.c_str();
		if (_stripTextureDir)
			value += GlobalTexturePrefix_get().size();
		gtk_entry_set_text(GTK_ENTRY(_targetEntry), value);
	}

	// Propagate the call up to the client (e.g. SurfaceInspector)
	if (_client != NULL) {
		_client->shaderSelectionChanged(shaderName);
	}

	// Get the shader, and its image map if possible
	IShader* shader = _selector.getSelectedShader();
	if (shader != NULL) {
		// Pass the call to the static member
		ShaderSelector::displayShaderInfo(shader, listStore);

		shader->DecRef();
	}
}
Beispiel #6
0
// Callback to redraw the GL widget
void ShaderSelector::_onExpose(GtkWidget* widget,
								GdkEventExpose* ev,
								ShaderSelector* self)
{
	// The scoped object making the GL widget the current one
	gtkutil::GLWidgetSentry sentry(widget);

	// Get the viewport size from the GL widget
	GtkRequisition req;
	gtk_widget_size_request(widget, &req);
	glViewport(0, 0, req.width, req.height);

	// Initialise
	glClearColor(0.3f, 0.3f, 0.3f, 0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glDisable(GL_DEPTH_TEST);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, req.width, 0, req.height, -100, 100);
	glEnable(GL_TEXTURE_2D);

	// Get the selected texture, and set up OpenGL to render it on
	// the quad.
	IShader* shader = self->getSelectedShader();
	if (shader == NULL)
		return;

	shader->DecRef();

	bool drawQuad = false;

	// This is an "ordinary" texture, take the editor image
	GLTexture* tex = shader->getTexture();
	if (tex != NULL) {
		glBindTexture(GL_TEXTURE_2D, tex->texture_number);
		drawQuad = true;
	}

	if (drawQuad) {
		// Calculate the correct aspect ratio for preview.
		float aspect = float(tex->width) / float(tex->height);

		float hfWidth, hfHeight;
		if (aspect > 1.0) {
			hfWidth = 0.5 * req.width;
			hfHeight = 0.5 * req.height / aspect;
		} else {
			hfHeight = 0.5 * req.width;
			hfWidth = 0.5 * req.height * aspect;
		}

		// Draw a quad to put the texture on
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		glColor3f(1, 1, 1);
		glBegin(GL_QUADS);
		glTexCoord2i(0, 1);
		glVertex2f(0.5*req.width - hfWidth, 0.5*req.height - hfHeight);
		glTexCoord2i(1, 1);
		glVertex2f(0.5*req.width + hfWidth, 0.5*req.height - hfHeight);
		glTexCoord2i(1, 0);
		glVertex2f(0.5*req.width + hfWidth, 0.5*req.height + hfHeight);
		glTexCoord2i(0, 0);
		glVertex2f(0.5*req.width - hfWidth, 0.5*req.height + hfHeight);
		glEnd();
	}
}