Jump to content
  • Advertisement
Sign in to follow this  
fms

Problem with floating-point textures.

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to load floating-point values through floating-point textures onto a screen aligned quad. But for some reason, the floating-point values do not overlap the pixels on the screen and returns me the values assgined to the quad when drawing the quad. Here is the source code:
##############################################################################################
#include <stdio.h>
#include <GL/glut.h>

#define XSCREEN 4 // width
#define YSCREEN 4 // height

GLfloat Texture[YSCREEN][XSCREEN][4];
GLuint Tex;
GLfloat buffer[YSCREEN * XSCREEN * 4];

void GLUTInit (int*, char**);
void Init (void);
void Display (void);
void Draw (void);
void ReadBack (void);
void Error (void);
void MakeTexture (void);
void MapTexture (void);

int main (int argc, char** argv)
{
	GLUTInit (&argc, argv);
	Init ();
	glutDisplayFunc (Display);
	glutMainLoop ();
	return 0;
} // main

void GLUTInit (int* argc, char** argv)
{
	glutInit (argc, argv);
	glutInitWindowSize (XSCREEN, YSCREEN); 
	glutInitDisplayMode (GLUT_RGBA | GLUT_ALPHA);
	glutCreateWindow ("glReadPixels");
} // GLUTInit

void Init (void)
{
	glClearColor (0.0, 0.0, 0.0, 1.0);
	glClearDepth (1.0f);
	MakeTexture ();
	glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
	MapTexture ();
} // Init

void Display (void)
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable (GL_TEXTURE_RECTANGLE_NV);
	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glBindTexture (GL_TEXTURE_RECTANGLE_NV, Tex);
	Draw ();
	ReadBack ();
	glDisable (GL_TEXTURE_RECTANGLE_NV);
} // Display

void Draw (void)
{	
	glViewport (0, 0, XSCREEN, YSCREEN);
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	glOrtho (0, XSCREEN, 0, YSCREEN, 0, 1);
	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity ();
	glBegin (GL_QUADS);
	glColor4f (1, 1, 1, 0);

		glTexCoord2f (0, 0);
		glVertex2f (0, 0);

		glTexCoord2f (XSCREEN, 0);
		glVertex2f (XSCREEN, 0);

		glTexCoord2f (XSCREEN, YSCREEN);
		glVertex2f (XSCREEN, YSCREEN);

		glTexCoord2f (0, YSCREEN);
		glVertex2f (0, YSCREEN);
	glEnd ();
	glFinish ();
} // Draw

void ReadBack (void)
{
	int i;
	FILE* Buffer;
	
	Buffer = fopen ("Buffer.raw", "w");
	if (NULL == Buffer)
	{
		printf ("File error\n");	
		exit (1);
	}
	Error ();
	glPixelStorei (GL_PACK_ALIGNMENT, 1);
	glReadPixels (0, 0, XSCREEN, YSCREEN, GL_RGBA, GL_FLOAT, buffer);
	Error ();
	for (i = 0; i < XSCREEN * YSCREEN * 4; i++)
	{
		fprintf (Buffer, "%f\n", buffer);
	}
	fclose (Buffer);
} // ReadTexture

void Error (void)
{
	GLenum errCode;
	const GLubyte* errString;

	if ((errCode = glGetError ()) != GL_NO_ERROR)
	{
		errString = gluErrorString (errCode);
		printf ("GL Error : %s\n", errString);
	}
} // Error

void MakeTexture (void)
{
	int i;
	int j;
	int c;

	c = 0;
	for (i = 0; i < YSCREEN; i++)
	{
		for (j = 0; j < XSCREEN; j++)
		{
			Texture[j][0] = c++;
			Texture[j][1] = c++;
			Texture[j][2] = c++;
			Texture[j][3] = c++;
		}
	}
} // MakeTexture

void MapTexture (void)
{
	Error ();
	glGenTextures (1, &Tex);
	glBindTexture (GL_TEXTURE_RECTANGLE_NV, Tex);
	glTexParameteri (GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri (GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_WRAP_T, GL_CLAMP);
	glTexParameteri (GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri (GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexImage2D (GL_TEXTURE_RECTANGLE_NV, 0, GL_FLOAT_RGBA32_NV, XSCREEN, YSCREEN, 0, GL_RGBA, GL_FLOAT, Texture);
	Error ();
} // MapTexture
##############################################################################################


Any help is highly appreciated. Thanks. - FMS [edit: added source tags -SiCrane]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!