Exemple #1
0
/*
===================
RB_ShowIntensity

Debugging tool to see how much dynamic range a scene is using.
The greatest of the rgb values at each pixel will be used, with
the resulting color shading from red at 0 to green at 128 to blue at 255
===================
*/
static void RB_ShowIntensity() {
	byte	*colorReadback;
	int		i, j, c;

	if ( !r_showIntensity.GetBool() ) {
		return;
	}

	colorReadback = (byte *)R_StaticAlloc( renderSystem->GetWidth() * renderSystem->GetHeight() * 4, TAG_RENDER_TOOLS );
	qglReadPixels( 0, 0, renderSystem->GetWidth(), renderSystem->GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, colorReadback );

	c = renderSystem->GetWidth() * renderSystem->GetHeight() * 4;
	for ( i = 0; i < c; i+=4 ) {
		j = colorReadback[i];
		if ( colorReadback[i+1] > j ) {
			j = colorReadback[i+1];
		}
		if ( colorReadback[i+2] > j ) {
			j = colorReadback[i+2];
		}
		if ( j < 128 ) {
			colorReadback[i+0] = 2*(128-j);
			colorReadback[i+1] = 2*j;
			colorReadback[i+2] = 0;
		} else {
			colorReadback[i+0] = 0;
			colorReadback[i+1] = 2*(255-j);
			colorReadback[i+2] = 2*(j-128);
		}
	}

	// draw it back to the screen
	qglLoadIdentity();
	qglMatrixMode( GL_PROJECTION );
	GL_State( GLS_DEPTHFUNC_ALWAYS );
	qglPushMatrix();
	qglLoadIdentity(); 
    qglOrtho( 0, 1, 0, 1, -1, 1 );
	qglRasterPos2f( 0, 0 );
	qglPopMatrix();
	GL_Color( 1, 1, 1 );
	globalImages->BindNull();
	qglMatrixMode( GL_MODELVIEW );

	qglDrawPixels( renderSystem->GetWidth(), renderSystem->GetHeight(), GL_RGBA , GL_UNSIGNED_BYTE, colorReadback );

	R_StaticFree( colorReadback );
}
Exemple #2
0
/*
===================
RB_ShowDepthBuffer

Draw the depth buffer as colors
===================
*/
static void RB_ShowDepthBuffer() {
	void	*depthReadback;

	if ( !r_showDepth.GetBool() ) {
		return;
	}

	qglPushMatrix();
	qglLoadIdentity();
	qglMatrixMode( GL_PROJECTION );
	qglPushMatrix();
	qglLoadIdentity(); 
    qglOrtho( 0, 1, 0, 1, -1, 1 );
	qglRasterPos2f( 0, 0 );
	qglPopMatrix();
	qglMatrixMode( GL_MODELVIEW );
	qglPopMatrix();

	GL_State( GLS_DEPTHFUNC_ALWAYS );
	GL_Color( 1, 1, 1 );
	globalImages->BindNull();

	depthReadback = R_StaticAlloc( renderSystem->GetWidth() * renderSystem->GetHeight()*4, TAG_RENDER_TOOLS );
	memset( depthReadback, 0, renderSystem->GetWidth() * renderSystem->GetHeight()*4 );

	qglReadPixels( 0, 0, renderSystem->GetWidth(), renderSystem->GetHeight(), GL_DEPTH_COMPONENT , GL_FLOAT, depthReadback );

#if 0
	for ( i = 0; i < renderSystem->GetWidth() * renderSystem->GetHeight(); i++ ) {
		((byte *)depthReadback)[i*4] = 
		((byte *)depthReadback)[i*4+1] = 
		((byte *)depthReadback)[i*4+2] = 255 * ((float *)depthReadback)[i];
		((byte *)depthReadback)[i*4+3] = 1;
	}
#endif

	qglDrawPixels( renderSystem->GetWidth(), renderSystem->GetHeight(), GL_RGBA , GL_UNSIGNED_BYTE, depthReadback );
	R_StaticFree( depthReadback );
}
Exemple #3
0
/*
==============
Z_DrawGrid
==============
*/
void Z_DrawGrid (void)
{
	float	zz, zb, ze;
	int		w, h;
	char	text[32];

	w = z.width/2 / z.scale;
	h = z.height/2 / z.scale;

	zb = z.origin[2] - h;
	if (zb < region_mins[2])
		zb = region_mins[2];
	zb = 64 * floor (zb/64);

	ze = z.origin[2] + h;
	if (ze > region_maxs[2])
		ze = region_maxs[2];
	ze = 64 * ceil (ze/64);

	// draw major blocks

	qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMAJOR]);

	qglBegin (GL_LINES);

	qglVertex2f (0, zb);
	qglVertex2f (0, ze);

	for (zz=zb ; zz<ze ; zz+=64)
	{
		qglVertex2f (-w, zz);
		qglVertex2f (w, zz);
	}

	qglEnd ();

	// draw minor blocks
	if (g_qeglobals.d_showgrid && g_qeglobals.d_gridsize*z.scale >= 4 &&
      g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR] != g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK])
	{
		qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR]);

		qglBegin (GL_LINES);
		for (zz=zb ; zz<ze ; zz+=g_qeglobals.d_gridsize)
		{
			if ( ! ((int)zz & 63) )
				continue;
			qglVertex2f (-w, zz);
			qglVertex2f (w, zz);
		}
		qglEnd ();
	}

	// draw coordinate text if needed

	qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDTEXT]);

	for (zz=zb ; zz<ze ; zz+=64)
	{
		qglRasterPos2f (-w+1, zz);
		sprintf (text, "%i",(int)zz);
		qglCallLists (strlen(text), GL_UNSIGNED_BYTE, text);
	}
}
Exemple #4
0
/*
==============
Z_DrawGrid
==============
*/
void Z_DrawGrid (void)
{
	float	zz, zb, ze;
	float	w, h;
	char	text[32];

	w = (z.width/2 / z.scale);
	h = (z.height/2 / z.scale);

	zb = z.origin[2] - h;
	if (zb < region_mins[2])
		zb = region_mins[2];
	zb = 64 * floor (zb/64);

	ze = z.origin[2] + h;
	if (ze > region_maxs[2])
		ze = region_maxs[2];
	ze = 64 * ceil (ze/64);

	// draw major blocks

	qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMAJOR]);

	if ( g_qeglobals.d_showgrid )
	{
	  if (g_qeglobals.d_gridsize < 128)
	  {
	    qglBegin (GL_LINES);

	    qglVertex2f (0, zb);
	    qglVertex2f (0, ze);

	    for (zz=zb ; zz<ze ; zz+=64)
	    {
	      qglVertex2f (-w, zz);
	      qglVertex2f (w, zz);
	    }

	    qglEnd ();
	  }
	  else
	  {
	    qglBegin (GL_LINES);

	    qglVertex2f (0, zb);
	    qglVertex2f (0, ze);

	    for (zz=zb ; zz<ze ; zz+=64)
	    {
        // d_gridsize >= 128 .. it's an int for sure
	      if ( ((int)zz & ((int)g_qeglobals.d_gridsize-1)) != 0 )
      		continue;

	      qglVertex2f (-w, zz);
	      qglVertex2f (w, zz);
	    }

	    qglEnd ();
	  }
	}

	// draw minor blocks
	if (g_qeglobals.d_showgrid && g_qeglobals.d_gridsize*z.scale >= 4 &&
      g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR] != g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK])
	{
		qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR]);

		qglBegin (GL_LINES);
		for (zz=zb ; zz<ze ; zz+=g_qeglobals.d_gridsize)
		{
			if ( ! ((int)zz & 63) )
				continue;
			qglVertex2f (-w, zz);
			qglVertex2f (w, zz);
		}
		qglEnd ();
	}

	// draw coordinate text if needed

	if ( g_qeglobals.d_savedinfo.show_coordinates)
	{
		qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDTEXT]);

		int step = (int)(g_qeglobals.d_gridsize > 64 ? g_qeglobals.d_gridsize : 64);
		zb = z.origin[2] - h;
		if (zb < region_mins[2])
			zb = region_mins[2];
		zb = step * floor (zb/step);

		for (zz=zb ; zz<ze ; zz+=step)
		{
			qglRasterPos2f (-w+(1/z.scale), zz);
			sprintf (text, "%i",(int)zz);
			gtk_glwidget_print_string(text);
		}
	}
}
Exemple #5
0
/*
==============
RenderBumpTriangles

==============
*/
static void RenderBumpTriangles( srfTriangles_t *lowMesh, renderBump_t *rb ) {
	int		i, j;

	RB_SetGL2D();

	qglDisable( GL_CULL_FACE );

	qglColor3f( 1, 1, 1 );

	qglMatrixMode( GL_PROJECTION );
	qglLoadIdentity();
	qglOrtho( 0, 1, 1, 0, -1, 1 );
	qglDisable( GL_BLEND );
	qglMatrixMode( GL_MODELVIEW );
	qglLoadIdentity();

	qglDisable( GL_DEPTH_TEST );

	qglClearColor(1,0,0,1);
	qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	qglColor3f( 1, 1, 1 );

	// create smoothed normals for the surface, which might be
	// different than the normals at the vertexes if the
	// surface uses unsmoothedNormals, which only takes the
	// normal from a single triangle.  We need properly smoothed
	// normals to make sure that the traces always go off normal
	// to the true surface.
	idVec3	*lowMeshNormals = (idVec3 *)Mem_ClearedAlloc( lowMesh->numVerts * sizeof( *lowMeshNormals ) );
	R_DeriveFacePlanes( lowMesh );
	R_CreateSilIndexes( lowMesh );	// recreate, merging the mirrored verts back together
	const idPlane *planes = lowMesh->facePlanes;
	for ( i = 0 ; i < lowMesh->numIndexes ; i += 3, planes++ ) {
		for ( j = 0 ; j < 3 ; j++ ) {
			int		index;

			index = lowMesh->silIndexes[i+j];
			lowMeshNormals[index] += (*planes).Normal();
		}
	}
	// normalize and replicate from silIndexes to all indexes
	for ( i = 0 ; i < lowMesh->numIndexes ; i++ ) {
		lowMeshNormals[lowMesh->indexes[i]] = lowMeshNormals[lowMesh->silIndexes[i]];
		lowMeshNormals[lowMesh->indexes[i]].Normalize();
	}


	// rasterize each low poly face
	for ( j = 0 ; j < lowMesh->numIndexes ; j+=3 ) {
		// pump the event loop so the window can be dragged around
		Sys_GenerateEvents();

		RasterizeTriangle( lowMesh, lowMeshNormals, j/3, rb );

		qglClearColor(1,0,0,1);
		qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
		qglRasterPos2f( 0, 1 );
		qglPixelZoom( glConfig.vidWidth / (float)rb->width, glConfig.vidHeight / (float)rb->height );
		qglDrawPixels( rb->width, rb->height, GL_RGBA, GL_UNSIGNED_BYTE, rb->localPic );
		qglPixelZoom( 1, 1 );
		qglFlush();
		GLimp_SwapBuffers();
	}

	Mem_Free( lowMeshNormals );
}
/*
==============
CZWnd::Z_DrawGrid
==============
*/
void CZWnd::Z_DrawGrid( void ) {
	float	zz, zb, ze;
	int		w, h;
	char	text[ 32 ];

	w = z.width / 2 / z.scale;
	h = z.height / 2 / z.scale;

// ---> sikk - Fixed Grid
//	int nSize = 1.0f / g_qeglobals.d_gridsize * 256;
	float fScale = 1.0f / g_qeglobals.d_gridsize * 8;
	int stepSize = g_qeglobals.d_gridsize * 8 * fScale / 2 / z.scale;
	if ( stepSize < g_qeglobals.d_gridsize * 8 ) {
		stepSize = g_qeglobals.d_gridsize * 8;
	} else {
		int i;
		for ( i = 1; i < stepSize; i <<= 1 ) {}
		stepSize = i;
	}
//	int stepSize = max( 64, g_qeglobals.d_gridsize );	// sikk - Larger Grid Sizes - Added
// <--- sikk - Fixed Grid

	zb = z.origin[2] - h;
	if ( zb < region_mins[ 2 ] ) {
		zb = region_mins[ 2 ];
	}
	zb = stepSize * floor( zb / stepSize );				// sikk - Larger Grid Sizes	- was 64

	ze = z.origin[2] + h;
	if ( ze > region_maxs[ 2 ] ) {
		ze = region_maxs[ 2 ];
	}
	ze = stepSize * ceil( ze / stepSize );				// sikk - Larger Grid Sizes	- was 64

	// draw minor blocks
	if ( //z.scale > fScale &&	// sikk - Fixed grid
		 g_qeglobals.d_showgrid &&
		 //g_qeglobals.d_gridsize * z.scale >= 4 &&
		!g_qeglobals.d_savedinfo.colors[ COLOR_GRIDMINOR ].Compare( g_qeglobals.d_savedinfo.colors[ COLOR_GRIDBACK ] ) ) {

		qglColor3fv( g_qeglobals.d_savedinfo.colors[ COLOR_GRIDMINOR ].ToFloatPtr() );
		qglBegin( GL_LINES );
		for ( zz = zb; zz < ze; zz += stepSize / 8 ) {
// ---> sikk - Fixed grid
			//if ( !( (int)zz & 63 ) ) {
			//	continue;
			//}
//<--- sikk - Fixed grid
			qglVertex2f( -w, zz );
			qglVertex2f( w, zz );
		}
		qglEnd();
	}

	// draw major blocks
	qglBegin( GL_LINES );
	qglColor3fv( g_qeglobals.d_savedinfo.colors[ COLOR_GRIDMAJOR ].ToFloatPtr() );
	qglVertex2f( 0, zb );
	qglVertex2f( 0, ze );
	for ( zz = zb; zz < ze; zz += stepSize ) {			// sikk - Larger Grid Sizes	- was 64
		if ( zz == 0 ) { 
			qglColor3fv( g_qeglobals.d_savedinfo.colors[ COLOR_GRIDTEXT ].ToFloatPtr() );
		} else {
			qglColor3fv( g_qeglobals.d_savedinfo.colors[ COLOR_GRIDMAJOR ].ToFloatPtr() );
		}
		qglVertex2f( -w, zz );
		qglVertex2f( w, zz );
	}
	qglEnd();

	// draw coordinate text if needed
	qglColor3fv( g_qeglobals.d_savedinfo.colors[ COLOR_GRIDTEXT ].ToFloatPtr() );

	for ( zz = zb; zz < ze; zz += stepSize ) {
		qglRasterPos2f( -w + 1, zz );
		sprintf( text, "%i", (int)zz );
		qglCallLists( strlen( text ), GL_UNSIGNED_BYTE, text );
	}
}
/*
 =======================================================================================================================
 =======================================================================================================================
 */
void CNewTexWnd::OnPaint() {

	CPaintDC	dc(this);	// device context for painting

	int nOld = g_qeglobals.d_texturewin.m_nTotalHeight;

	//hdcTexture = GetDC();
	if (!qwglMakeCurrent(dc.GetSafeHdc(), win32.hGLRC)) {
		common->Printf("ERROR: wglMakeCurrent failed..\n ");
	}
	else {
		const char	*name;
		qglClearColor
		(
			g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][0],
			g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][1],
			g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][2],
			0
		);
		qglViewport(0, 0, rectClient.Width(), rectClient.Height());
		qglScissor(0, 0, rectClient.Width(), rectClient.Height());
		qglMatrixMode(GL_PROJECTION);
		qglLoadIdentity();
		qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		qglDisable(GL_DEPTH_TEST);
		qglDisable(GL_BLEND);
		qglOrtho(0, rectClient.Width(), origin.y - rectClient.Height(), origin.y, -100, 100);
		qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

		// init stuff
		current.x = 8;
		current.y = -8;
		currentRow = 0;
		currentIndex = 0;
		while (1) {
			const idMaterial *mat = NextPos();
			if (mat == NULL) {
				break;
			}

			int width = mat->GetEditorImage()->uploadWidth * ((float)g_PrefsDlg.m_nTextureScale / 100);
			int height = mat->GetEditorImage()->uploadHeight * ((float)g_PrefsDlg.m_nTextureScale / 100);

			// Is this texture visible?
			if ((draw.y - height - FONT_HEIGHT < origin.y) && (draw.y > origin.y - rectClient.Height())) {
				// if in use, draw a background
				qglLineWidth(1);
				qglColor3f(1, 1, 1);
				globalImages->BindNull();
				qglBegin(GL_LINE_LOOP);
				qglVertex2f(draw.x - 1, draw.y + 1 - FONT_HEIGHT);
				qglVertex2f(draw.x - 1, draw.y - height - 1 - FONT_HEIGHT);
				qglVertex2f(draw.x + 1 + width, draw.y - height - 1 - FONT_HEIGHT);
				qglVertex2f(draw.x + 1 + width, draw.y + 1 - FONT_HEIGHT);
				qglEnd();

				// Draw the texture
				float	fScale = (g_PrefsDlg.m_bHiColorTextures == TRUE) ? ((float)g_PrefsDlg.m_nTextureScale / 100) : 1.0;

				mat->GetEditorImage()->Bind();
				QE_CheckOpenGLForErrors();
				qglColor3f(1, 1, 1);
				qglBegin(GL_QUADS);
				qglTexCoord2f(0, 0);
				qglVertex2f(draw.x, draw.y - FONT_HEIGHT);
				qglTexCoord2f(1, 0);
				qglVertex2f(draw.x + width, draw.y - FONT_HEIGHT);
				qglTexCoord2f(1, 1);
				qglVertex2f(draw.x + width, draw.y - FONT_HEIGHT - height);
				qglTexCoord2f(0, 1);
				qglVertex2f(draw.x, draw.y - FONT_HEIGHT - height);
				qglEnd();

				// draw the selection border
				if ( !idStr::Icmp(g_qeglobals.d_texturewin.texdef.name, mat->GetName()) ) {
					qglLineWidth(3);
					qglColor3f(1, 0, 0);
					globalImages->BindNull();

					qglBegin(GL_LINE_LOOP);
					qglVertex2f(draw.x - 4, draw.y - FONT_HEIGHT + 4);
					qglVertex2f(draw.x - 4, draw.y - FONT_HEIGHT - height - 4);
					qglVertex2f(draw.x + 4 + width, draw.y - FONT_HEIGHT - height - 4);
					qglVertex2f(draw.x + 4 + width, draw.y - FONT_HEIGHT + 4);
					qglEnd();

					qglLineWidth(1);
				}

				// draw the texture name
				globalImages->BindNull();
				qglColor3f(1, 1, 1);
				qglRasterPos2f(draw.x, draw.y - FONT_HEIGHT + 2);

				// don't draw the directory name
				for (name = mat->GetName(); *name && *name != '/' && *name != '\\'; name++) {
					;
				}

				if (!*name) {
					name = mat->GetName();
				}
				else {
					name++;
				}
				qglCallLists(strlen(name), GL_UNSIGNED_BYTE, name);
				//qglCallLists(va("%s -- %d, %d" strlen(name), GL_UNSIGNED_BYTE, name);
			} 
		}

		g_qeglobals.d_texturewin.m_nTotalHeight = abs(draw.y) + 100;

		// reset the current texture
		globalImages->BindNull();
		qglFinish();
		qwglSwapBuffers(dc.GetSafeHdc());
		TRACE("Texture Paint\n");
	}

	if (g_PrefsDlg.m_bTextureScrollbar && (m_bNeedRange || g_qeglobals.d_texturewin.m_nTotalHeight != nOld)) {
		m_bNeedRange = false;
		SetScrollRange(SB_VERT, 0, g_qeglobals.d_texturewin.m_nTotalHeight, TRUE);
	}

	//ReleaseDC(hdcTexture);
}