Ejemplo n.º 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 = 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();
}
Ejemplo n.º 2
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();
	}
Ejemplo n.º 3
0
// Create the Tree View
GtkWidget* ShaderSelector::createTreeView() {
	// Tree model
	GtkTreeStore* store = gtk_tree_store_new(N_COLUMNS,
											G_TYPE_STRING, // display name in tree
											G_TYPE_STRING, // full shader name
											GDK_TYPE_PIXBUF);

	// Instantiate the helper class that populates the tree according to the paths
	gtkutil::VFSTreePopulator populator(store);

	ShaderNameVisitor func(populator, _prefixes);
	GlobalShaderSystem().foreachShaderName(func);

	// Now visit the created GtkTreeIters to load the actual data into the tree
	DataInserter inserter;
	populator.forEachNode(inserter);

	// Tree view
	_treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(_treeView), FALSE);
	g_object_unref(store); // tree view owns the reference now

	// Single visible column, containing the directory/shader name and the icon
	gtk_tree_view_append_column(GTK_TREE_VIEW(_treeView),
								gtkutil::IconTextColumn(_("Value"),
														NAME_COL,
														IMAGE_COL));

	// Set the tree store to sort on this column
	gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), NAME_COL, GTK_SORT_ASCENDING);

	// Use the TreeModel's full string search function
	gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(_treeView), gtkutil::TreeModel::equalFuncStringContains, NULL, NULL);

	// Get selection and connect the changed callback
	_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(_treeView));
	g_signal_connect(G_OBJECT(_selection),
					"changed",
					G_CALLBACK(_onSelChange),
					this);

	// Pack into scrolled window and frame
	return gtkutil::ScrolledFrame(_treeView);
}
Ejemplo n.º 4
0
// Get the selected shader
IShader* ShaderSelector::getSelectedShader() {
	return GlobalShaderSystem().getShaderForName(getSelection());
}
Ejemplo n.º 5
0
void OpenGLShader::constructNormalShader (const std::string& name)
{
	// construction from IShader
	m_shader = GlobalShaderSystem().getShaderForName(name);

	OpenGLState& state = appendDefaultPass();

	state.m_texture = m_shader->getTexture()->texture_number;

	state.m_state = RENDER_FILL | RENDER_TEXTURE_2D | RENDER_DEPTHTEST | RENDER_COLOURWRITE | RENDER_LIGHTING
			| RENDER_SMOOTH;
	state.m_state |= RENDER_CULLFACE;
	if ((m_shader->getFlags() & QER_ALPHATEST) != 0) {
		state.m_state |= RENDER_ALPHATEST;
		state.m_colour[3] = 0.25;
		IShader::EAlphaFunc alphafunc;
		m_shader->getAlphaFunc(&alphafunc, &state.m_alpharef);
		switch (alphafunc) {
		case IShader::eAlways:
			state.m_alphafunc = GL_ALWAYS;
		case IShader::eEqual:
			state.m_alphafunc = GL_EQUAL;
		case IShader::eLess:
			state.m_alphafunc = GL_LESS;
		case IShader::eGreater:
			state.m_alphafunc = GL_GREATER;
		case IShader::eLEqual:
			state.m_alphafunc = GL_LEQUAL;
		case IShader::eGEqual:
			state.m_alphafunc = GL_GEQUAL;
		}
	}

	state.m_colour = Vector4(m_shader->getTexture()->color, 1.0);

	if (isTransparent(m_shader->getName())) {
		state.m_state |= RENDER_BLEND;
		state.m_state |= RENDER_DEPTHWRITE;
		state.m_colour = Vector4(1.0, 1.0, 1.0, 0.4);
		state.m_sort = OpenGLState::eSortTranslucent;
	} else if ((m_shader->getFlags() & QER_TRANS) != 0) {
		state.m_state |= RENDER_BLEND;
		state.m_colour[3] = m_shader->getTrans();
		BlendFunc blendFunc = m_shader->getBlendFunc();
		state.m_blend_src = convertBlendFactor(blendFunc.m_src);
		state.m_blend_dst = convertBlendFactor(blendFunc.m_dst);
		if (state.m_blend_src == GL_SRC_ALPHA || state.m_blend_dst == GL_SRC_ALPHA) {
			state.m_state |= RENDER_DEPTHWRITE;
		}
		state.m_sort = OpenGLState::eSortTranslucent;
	} else if (m_shader->getTexture()->hasAlpha) {
		state.m_state |= RENDER_BLEND;
		state.m_state |= RENDER_DEPTHWRITE;
		state.m_sort = OpenGLState::eSortTranslucent;
	} else {
		state.m_state |= RENDER_DEPTHWRITE;
		state.m_sort = OpenGLState::eSortFullbright;
	}

	m_shader->forEachLayer(ShaderLayerVisitor(*this));
}