GIDForums  

Go Back   GIDForums > Computer Programming Forums > OpenGL Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Jun-2006, 08:07
McFury McFury is offline
New Member
 
Join Date: Apr 2004
Posts: 3
McFury is on a distinguished road

Texture mapping (C and OpenGL)


Hiya
Im writing a program in C using openGL (GLUT) and im having a little trouble with the function to process textures (RAW files). It compiles ok but when i bind the texture in my display function and apply it to a quad it does not display it at runtime (just has a simple RGB default colour i had assigned with glColor3f). It has to be because its not allocating the memory correctly with the malloc i think? but i cant think of a way to just get it working, can anyone please maybe help me.. Pretty please? Im getting really frustrated lol.

Below is the texture processing function:

CPP / C++ / C Code:
// load a 256x256 RGB .RAW file as a texture
GLuint LoadTextureRAW( const char * filename, int wrap ) {

  GLuint texture;
  int width, height;
  BYTE * data;
  FILE * file;

  // open texture data
  file = fopen( filename, "rb" );
  if ( file == NULL ) return 0;

  // allocate buffer
  width	 = 256;
  height = 256;
  data = (BYTE*)malloc( width * height * 3 );  // <---- is this right?

  // read texture data
  fread( data, width * height * 3, 1, file );
  fclose( file );

  // allocate a texture name
  glGenTextures( 1, &texture );

  // select our current texture
  glBindTexture( GL_TEXTURE_2D, texture );

  // select modulate to mix texture with color for shading
  glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

  // when texture area is small, bilinear filter the closest MIP map
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
  // when texture area is large, bilinear filter the first MIP map
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

  // if wrap is true, the texture wraps over at the edges (repeat)
  //       ... false, the texture ends at the edges (clamp)
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ? GL_REPEAT : GL_CLAMP );
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ? GL_REPEAT : GL_CLAMP );

  // build our texture MIP maps
  gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );

  // free buffer
  free( data );

  return texture;
}

Im using it like this (just showing the parts that matter):


CPP / C++ / C Code:
GLuint texture;
texture = LoadTextureRAW("bush.raw", TRUE);

glBindTexture(GL_TEXTURE_2D, texture);

glBegin(GL_QUADS);				
	glColor3f(0.0, 0.6, 0.0); //Just the default colour
	glTexCoord2f(0.0,0.0);
	glVertex3f(-1000.0, 0.0, 1000.0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(1000.0, 0.0, 1000.0);
	glTexCoord2f(1.0,1.0); 
	glVertex3f(1000.0, 0.0, -1000.0);
	glTexCoord2f(1.0,0.0); 
	glVertex3f(-1000.0, 0.0, -1000.0);		
glEnd();

I really need to get this working

Thanks.
Last edited by cable_guy_67 : 02-Jun-2006 at 09:12. Reason: Please enclose c code in [c] ... [/c] tags
 
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenGL in Normal FLTK Windows automatedreason FLTK Forum 2 25-Apr-2008 05:44
What is OpenGL? Shrikharan OpenGL Programming 6 21-Dec-2005 17:47
C++ game programming OpenGL oozsakarya OpenGL Programming 2 13-Nov-2005 13:50
nVidia & OpenGL Problems in windows XP marjasin Computer Hardware Forum 21 30-Aug-2004 00:57
OpenGL always reports error mvt OpenGL Programming 2 04-Jun-2004 06:42

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:24.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.