Sign in to follow this  
Sw00sh

OpenGL Textur Mapping problem

Recommended Posts

Hi guys, I'm new in opengl programming and I have a question respectively a problem. At first same codesnippets:
#ifndef FIBS_H
#define FIBS_H

#include	<gl\glaux.h>	

class BMP{
private:
	GLuint	texture[1];
	AUX_RGBImageRec *LoadBMP(char *Filename);
public:
	BMP(void);
	int LoadGLTextures(void);
	GLuint getTextur(void);
	GLuint* getTexturPointer(void);
	~BMP(void);
};

#endif

#include	<windows.h>							// Header File For Windows
#include	<stdio.h>							// Header File For Standard Input/Output ( NEW )
#include	<gl\glaux.h>	

#include "BMP.h"

AUX_RGBImageRec *BMP::LoadBMP(char *Filename){				// Loads A Bitmap Image
	FILE *File=NULL;									// File Handle
	if (!Filename)										// Make Sure A Filename Was Given
		return NULL;									// If Not Return NULL
	File=fopen(Filename,"r");							// Check To See If The File Exists
	if (File){											// Does The File Exist?
		fclose(File);									// Close The Handle
		return auxDIBImageLoad(Filename);				// Load The Bitmap And Return A Pointer
	}
	return NULL;										// If Load Failed Return NULL
}

BMP::BMP(void){
}

int BMP::LoadGLTextures(void){									// Load Bitmaps And Convert To Textures
	int Status=FALSE;									// Status Indicator
	AUX_RGBImageRec *TextureImage[1];					// Create Storage Space For The Texture
	memset(TextureImage,0,sizeof(void *)*1);           	// Set The Pointer To NULL
	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
	if (TextureImage[0]=LoadBMP("Data/NeHe.bmp")){
		Status=TRUE;									// Set The Status To TRUE
		glGenTextures(1, &texture[0]);					// Create The Texture
		// Typical Texture Generation Using Data From The Bitmap
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	}
	if (TextureImage[0]){									// If Texture Exists
		if (TextureImage[0]->data){							// If Texture Image Exists
			free(TextureImage[0]->data);					// Free The Texture Image Memory
		}
		free(TextureImage[0]);								// Free The Image Structure
	}
	return Status;										// Return The Status
}

GLuint BMP::getTextur(void){
	return BMP::texture[0];
}

GLuint* BMP::getTexturPointer(void){
	return BMP::texture;
}

BMP::~BMP(void){
}

#ifndef FIBS_C
#define FIBS_C

#include "BMP.h"

class Aquarium{
private:
	BMP* bitmap;
	int init(GLvoid);
	void drawAquariumPart(float xCoord, float yCoord, float zCoord, float xSize, float ySize, float zSize);
	void drawWater(void);
	void drawQuad(void);
	void drawWasserPflanzen(void);

public:
	Aquarium(void);
	~Aquarium(void);
	void drawAquarium(void);
};
#endif

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <gl\glut.h>

#include "BMP.h"
#include "Aquarium_Objekt.h"

int Aquarium::init(GLvoid){								// All Setup For OpenGL Goes Here
	if (!Aquarium::bitmap->LoadGLTextures())			// Jump To Texture Loading Routine ( NEW )
		return FALSE;									// If Texture Didn't Load Return FALSE
	return TRUE;										// Initialization Went OK
}

// Methode zum Zeichnen eines Teils des Aquariums
// x-, y- und z-Koordinate, sowie x-, y- und z-Groesse werden uebergeben
void Aquarium::drawAquariumPart(float xCoord, float yCoord, float zCoord, float xSize, float ySize, float zSize){	
	// Legt die aktuelle Matrix auf den Stack
	glPushMatrix();	
		// Setzt die aktuelle Farbe auf hellblau
		glColor4f(0.3, 0.3, 0.5, 0.7);
		// Verschiebt den erzeugten Würfel um xCoord, yCoord, zCoord
		glTranslatef(xCoord, yCoord, zCoord);
		// Streckt den erzeugten Würfel um xSize, ySize, zSize
		glScalef(xSize, ySize, zSize);
		// Erzeugt einen soliden Würfel, der gestreckt und verschoben wird
		glutSolidCube(1);
	// Nimmt die aktuelle Matrix vom Stack
	glPopMatrix();

} // end drawAquariumPart


	// Methode zum Zeichnen des Wassers
void Aquarium::drawWater(void){
	// Transparenz aktivieren
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	// Legt die aktuelle Matrix auf den Stack
	glPushMatrix();	
		// Setzt die aktuelle Farbe auf hellblau
		glColor4f(0.15, 0.45, 0.5, 0.2);
		// Verschiebt den erzeugten Würfel um xCoord, yCoord, zCoord
		glTranslatef(15, 5, -7.6);
		// Streckt den erzeugten Würfel um xSize, ySize, zSize
		glScalef(24.6, 9.6, 9.8);
		// Erzeugt einen soliden Würfel, der gestreckt und verschoben wird
		glutSolidCube(1);
	// Nimmt die aktuelle Matrix vom Stack
	glPopMatrix();
	// Transparenz deaktivieren
	glDisable(GL_BLEND);
} // end drawWater

void Aquarium::drawQuad(void){
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, Aquarium::bitmap->getTextur());

	glPushMatrix();	
	glTranslatef(15, 5, -10);	

	glBegin(GL_QUADS);
		// Front Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  0.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  0.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  0.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  0.0f);	// Bottom Right Of The Texture and Quad
	glEnd();
	glPopMatrix();
	glDisable(GL_TEXTURE_2D); /* disable texture mapping */
}

void Aquarium::drawWasserPflanzen(void){
	this->drawQuad();
}

Aquarium::Aquarium(){
	Aquarium::bitmap = new BMP();
	if(!this->init())
		printf("Konnte Textur nicht laden\n");
        else
	        printf("Laden der Textur erfolgreich\n");
}

Aquarium::~Aquarium(){}

void Aquarium::drawAquarium(){
	this->drawWasserPflanzen();
	this->drawWater();
	// Transparenz aktivieren
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	// Erzeugt vordere Scheibe
	drawAquariumPart(15,5,-2.6,25,10,0.2);
	// Erzeugt linke Scheibe
	drawAquariumPart(2.6,5,-7.5,0.2,10,10);
	// Erzeugt rechte Scheibe
	drawAquariumPart(27.4,5,-7.5,0.2,10,10);
	// Erzeugt hintere Scheibe
	drawAquariumPart(15,5,-12.6,25,10,0.2);
	// Erzeugt untere Scheibe
	drawAquariumPart(15,0.1,-7.5,24.6,0.2,10);
	// Transparenz deaktivieren
	glDisable(GL_BLEND);
} // end drawAquarium

And this is my display function
void display(void)
{
	if (deltaMove)
		moveMeFlat(deltaMove);
	if (deltaAngle) {
		angle += deltaAngle;
		orientMe(angle);
	}

	frame++;
	time=glutGet(GLUT_ELAPSED_TIME);
	if (time - timebase > 1000) {
		printf("FPS:%4.2f\n",frame*1000.0/(time-timebase));
		timebase = time;		
		frame = 0;
	}

	// Das bisherige Bild wird gelöscht indem das komplette Bild mit der Hintergrundfarbe überdeckt wird.
	// Dazu wird das Bild komplett in Hintergrundfarbe gezeichnet und Verdeckungsrechnung initialisiert.
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	for(int x =0; x<fischanzahl; x++){
		fische[x]->moveFisch();
		fische[x]->drawFisch();
	}
	
	spotlight->drawSpotLight();
	tisch->drawTable();
	aquarium->drawAquarium();
	// ---

	// Sorge dafür, dass wirklich alle glBefehle abgearbeitet und nicht gepuffert werden
	glFlush();

	// Vertausche die Backbuffer und Frontbuffer: das fertig
	// gezeichnete Bild soll jetzt angezeigt werden
	glutSwapBuffers();

	// Sorge dafür, dass das Bild im nächsten Schleifendurchlauf
	// der glutMainLoop wieder gezeichnet wird
	glutPostRedisplay();

} // end display

Now my problem... i do not get the textur on the quad. I have no idea why :) Perhaps anybody can help me.

Share this post


Link to post
Share on other sites
Where are you telling it what texture to use? Also where are the definitions for your Aquarium class? You show us they are there but not what is inside. You draw function makes calls to it but we cant see that code, which is a major suspect in something like this.

90% of my texture problems have been loading problems or not setting the correct texture value. For loading make sure you have a good error report stratagy to let you know if something failed

Share this post


Link to post
Share on other sites
Ok sorry for the bad information i'v gave :)

in the class BMP under LoadGLTextures, there i tell to use a bmp file. Than under LoadBMP i load this bmp file. After that i create the texture in LoadGLTextures -> glGenTextures(1, &texture[0]); // Create The Texture


To get accecc on this textur i wrote this to functions

GLuint BMP::getTextur(void){
return BMP::texture[0];
}

GLuint* BMP::getTexturPointer(void){
return BMP::texture;
}



I call this functions under the Aquarium class in void Aquarium::drawQuad(void).

I think there is no error on creating the texture in the memory, because LoadGLTextures returns true if all is ok.

Thanks for the fast replay :)

Share this post


Link to post
Share on other sites
Hi.

Try to work with glIsTexture, glGetError and glGetTexImage at particular sections,
so it might be more clear to figure out where the problem lies.

For example:
In your render function, test if the pixels are uploaded, with glGetTexImage.
or,
after glTexImage2D make a call to glGetError, to figure out, if you have
specified wrong parameters.

First, try this.

int BMP::LoadGLTextures(void){ // Load Bitmaps And Convert To Textures
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP("Data/NeHe.bmp")){
Status=TRUE; // Set The Status To TRUE
glGenTextures(1, &texture[0]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
////////////////////////////////////////////////////////////////////////
///////////// HERE, make modi, and test err with the debugger.
GLenum err = glGetError() ;
////////////////////////////////////////////////////////////////////////

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
if (TextureImage[0]){ ...




Alex

Share this post


Link to post
Share on other sites
Ok,

i think you guys are right. When i debugg i saw this:

On this line "(TextureImage[0]=LoadBMP("Data/NeHe.bmp"))" i get the value 'î' in TextureImage[0]->data (i think that not enough for a whole bmp file???), in TextureImage[0]->sizeX and ->sizeY is the value 256. 256 is the right value (size of the pic) for the bmp file. But i guess there is an error in ->data.

In texture i have got the value "3452816845" it is not null or something like that.

Share this post


Link to post
Share on other sites
Hi.

If you think that there is a error within ->data, so make an array on the stack
put the pixels in there and look over it with the debugger to ensure, that this might be a problem.
Another way to figure out data values which are stored on the heap, I cant deliver.

But I think, the char 'î' is just the first color value component of the pixel data.

And as I said, use glError, glIsTexture and/or glGetTexImage at particular sections to reveal problems.

And also another good solution is to put the code to be tested into a more
simple environment, to see how exactly it works.

Alex

P.S.
Every code I saw till now has utilized this

glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ) ;



Maybe this makes a problem. My code works without it, but who knows!?
Put it in front of the glTexImage2D() call.

Share this post


Link to post
Share on other sites
No change....

i don't know what to do now... how do you guys read in textures and bind it on a quad? Could you give me same inspiration or examples, how to get a texture on the f***ing quad :-)

Thanks a lot

Share this post


Link to post
Share on other sites
First of all, chill out.

Second.
1.) How sure are you that the texture is loaded?!
2.) How sure are you that there is no problem with glTexImage2D?!
For example, the texels arent uploaded...
or the texture is not pow of 2.
3.) How sure are you that the texture is bound? Hence 2.) must be
erroneous.
4.) Have you set all necessary parameters, for texturing.
5.) Have you used glBend* or something, so maybe you have fogotten
to put parameters back to GL_ADD or similar, for example when you have activated
glBendEquation with GL_ZERO, so the texture isnt drawn because of this.
Call glDisable(GL_BLEND) to avoid problems coming from this direction.

Thrid.
Get rid of all the geometry which mustn't be drawn and just draw one simple geometric obj, so you can deduce what exacly went wrong!!!

The most important thing is, make it as simple as possible, e.g. use a single and simple Quad, and put your texture on it, and not on your most complex geometry if you havent textured before.
This might sound trivial and stupid, but this is your only chance to get organized.
After successfully putting your texture onto the Quad, you can use an arbi geometry.

But first, try to answer the questions above, to give some more information!

Alex

Share this post


Link to post
Share on other sites
Chilling is that what i need :)

Ok now i answer your questions.

1.) How sure are you that the texture is loaded?!

Arm, not realy sure... but when i look to the ->data i think this is not enough for a whole file... if it is the first color of die pic, where is the rest?

2.) How sure are you that there is no problem with glTexImage2D?!
For example, the texels arent uploaded...
or the texture is not pow of 2.

Im pretty sure, because i copied it from link. When i run this it works... only in my workspace it don't wanna put the texture on the quad.

3.) How sure are you that the texture is bound? Hence 2.) must be
erroneous.

I don't realy know what you mean, but i guess you mean this:

void Aquarium::drawWasserPflanzen(void){
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Aquarium::bitmap->getTextur());
this->drawQuad();
glDisable(GL_TEXTURE_2D); /* disable texture mapping */
}



4.) Have you set all necessary parameters, for texturing.

Again i'm not pretty sure, i try to figure is out. But when i take a look on the lesson above, i think i have all necessary parameters.

5.) Have you used glBend* or something, so maybe you have fogotten ...

No they are all disabled.

Thrid.
Get rid of all the geometry which mustn't be drawn and just draw one simple geometric obj, so you can deduce what exacly went wrong!!!.....

I only sure a quad

void Aquarium::drawQuad(void){
glPushMatrix();
glTranslatef(15, 5, -10);
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f); // Bottom Right Of The Texture and Quad
glEnd();
glPopMatrix();

}



I hope you can help me :)

Share this post


Link to post
Share on other sites
I don't have the time right now to sift through your code but I will try and offer what little I can at the moment.

To get a texture going you

1) You have to set up blending when you init OpenGL. E.G. you must enable blending blah blah. If you don't you can load textures fine and still not get anything.

2) you must set your texture(which I think you are from the looks of it.)

3) be loading the texture correctly. Which is the most complicated error prone part. Now since you are most likly having problems with your BMP loader I'm going to recommend you toss the code out all together. Reason being you're better off having a loader for say TGA files. BMP is kinda the easiest but it's not the best format to be using. More than likely your are going to go though this all again with a better format. So just skip past all this and move on.

I'm going to recommend TGA because it supports some basic compression, supports alpha channels, is highly supported in both code and in art programs. All that means is you can have smaller files, have everything you need for various texturing, and won't have any trouble finding coding examples or programs to handle the art.

Share this post


Link to post
Share on other sites
Ok i tried it with a tga loader... no change... when i debugg the GLubyte *imageData; is empty.... i think thats not realy good :). But the function returns a true. But in ->texID there is an ID. So it should be right :) ???

Here is the function:
I copied from this board.


bool BMP::LoadTGA(TextureImage *texture, char *filename){ // Loads A TGA File Into Memory
GLubyte TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0}; // Uncompressed TGA Header
GLubyte TGAcompare[12]; // Used To Compare TGA Header
GLubyte header[6]; // First 6 Useful Bytes From The Header
GLuint bytesPerPixel; // Holds Number Of Bytes Per Pixel Used In The TGA File
GLuint imageSize; // Used To Store The Image Size When Setting Aside Ram
GLuint temp; // Temporary Variable
GLuint type=GL_RGBA; // Set The Default GL Mode To RBGA (32 BP
FILE *file = fopen(filename, "rb"); // Open The TGA File

if( file==NULL || // Does File Even Exist?
fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) || // Are There 12 Bytes To Read?
memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0 || // Does The Header Match What We Want?
fread(header,1,sizeof(header),file)!=sizeof(header)) // If So Read Next 6 Header Bytes
{
if (file == NULL) // Did The File Even Exist? *Added Jim Strong*
return false; // Return False
else{
fclose(file); // If Anything Failed, Close The File
return false; // Return False
}
}
texture->width = header[1] * 256 + header[0]; // Determine The TGA Width (highbyte*256+lowbyte)
texture->height = header[3] * 256 + header[2]; // Determine The TGA Height (highbyte*256+lowbyte)

if( texture->width <=0 || // Is The Width Less Than Or Equal To Zero
texture->height <=0 || // Is The Height Less Than Or Equal To Zero
(header[4]!=24 && header[4]!=32)) // Is The TGA 24 or 32 Bit?
{
fclose(file); // If Anything Failed, Close The File
return false; // Return False

}
texture->bpp = header[4]; // Grab The TGA's Bits Per Pixel (24 or 32)
bytesPerPixel = texture->bpp/8; // Divide By 8 To Get The Bytes Per Pixel
imageSize = texture->width*texture->height*bytesPerPixel; // Calculate The Memory Required For The TGA Data
texture->imageData=(GLubyte *)malloc(imageSize); // Reserve Memory To Hold The TGA Data

if( texture->imageData==NULL || // Does The Storage Memory Exist?
fread(texture->imageData, 1, imageSize, file)!=imageSize) // Does The Image Size Match The Memory Reserved?
{
if(texture->imageData!=NULL) // Was Image Data Loaded
free(texture->imageData); // If So, Release The Image Data
fclose(file); // Close The File
return false; // Return False
}

for(GLuint i=0; i<int(imageSize); i+=bytesPerPixel){ // Loop Through The Image Data // Swaps The 1st And 3rd Bytes ('R'ed and 'B'lue)
temp=texture->imageData[i]; // Temporarily Store The Value At Image Data 'i'
texture->imageData[i] = texture->imageData[i + 2]; // Set The 1st Byte To The Value Of The 3rd Byte
texture->imageData[i + 2] = temp; // Set The 3rd Byte To The Value In 'temp' (1st Byte Value)
}
fclose (file);
// Close The File
// Build A Texture From The Data
glGenTextures(1, &texture[0].texID); // Generate OpenGL texture IDs
glBindTexture(GL_TEXTURE_2D, texture[0].texID); // Bind Our Texture
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered

if (texture[0].bpp==24) // Was The TGA 24 Bits
type=GL_RGB;
// If So Set The 'type' To GL_RGB
glTexImage2D(GL_TEXTURE_2D, 0, type, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData);
return true; // Texture Building Went Ok, Return True
}





Are there any errors or difficulties, when i use this struct from the BMP.h header?
Here is the new header of BMP:

#ifndef FIBS_H
#define FIBS_H

#include <gl\glaux.h>

typedef struct{ // Create A Structure
GLubyte *imageData; // Image Data (Up To 32 Bits)
GLuint bpp; // Image Color Depth In Bits Per Pixel.
GLuint width; // Image Width
GLuint height; // Image Height
GLuint texID; // Texture ID Used To Select A Texture
} TextureImage;

class BMP{
private:
GLuint texture[1];
TextureImage textures[1];
AUX_RGBImageRec *LoadBMP(char *Filename);

public:
BMP(void);
bool LoadTGA(TextureImage *texture, char *filename);
int LoadGLTextures(void);
GLuint getTextur(void);
GLuint* getTexturPointer(void);
~BMP(void);
};

#endif





I use this struct in my Aquarium.cpp above. I think this is not the problem... the fileloader finds the file, but it do not write any data to imageData.

I don't understand this^^ :-)

Thanks
kAi

EDIT:

Ok I saw its right that the imageData has not value^^. Furthermore i have no idea

[Edited by - Sw00sh on June 10, 2007 3:42:42 PM]

Share this post


Link to post
Share on other sites
your Image Data shows up null because it is supposed to. Once the texture is created it get freed.

Happens right here

Quote:

if(texture->imageData!=NULL) // Was Image Data Loaded
free(texture->imageData); // If So, Release The Image Data
fclose(file);


Its common procedure otherwise your textures would eat up BOTH Video Ram and system ram.

Share this post


Link to post
Share on other sites
Can I see your initGL() function?


should look something like this

int initGL(GLvoid)
{
logfile << "initGL called. Setting up OpenGL.\n";
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix

glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
BuildDisLists(); //build long term lists

return true; // Initialization Went OK

}//end InitGL

Share this post


Link to post
Share on other sites
@Goober King:

You dont have to enable blending in order to use textures!
Also see tutorial at GameDev... (If you dont believe me)

@Sw00sh:

Dont worry about the loader!
If you have it from NeHe, it must work!

Do me a favour.

Please put an glGetError behind glTexImage2D and behind the glBindTexture
functions, and than, set a breakpoint behind them and then have a look
what the error is.
Is is 0, so there is no problem, is it differnt from zero, so have a look here
opengl SDK Doc

and see what errors exist.

If there is no error, we have to look more precisely.

Alex

Share this post


Link to post
Share on other sites
I get the error code 1282.

I checked this things from the SDK:
Quote:

GL_INVALID_OPERATION is generated if internalFormat is GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, or GL_DEPTH_COMPONENT32, and format is not GL_DEPTH_COMPONENT.

GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER target and the buffer object's data store is currently mapped.

GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER target and the data would be unpacked from the buffer
object such that the memory reads required would exceed the data store size.

GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER target and data is not evenly divisible into the number of bytes needed to store in memory a datum indicated by type.

GL_INVALID_OPERATION is generated if glTexImage2D is executed between the execution of glBegin and the corresponding execution of glEnd.


My internalFormat is GL_DEPTH_TEST ... if this is mean :)
I don't use a buffer...btw what is a buffer object?
And i checked if i used glTexImage2D between glBegin and glEnd.

But we know there is an error... thats something positive :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Goober King
Can I see your initGL() function?


should look something like this
*** Source Snippet Removed ***



int Aquarium::init(GLvoid){ // All Setup For OpenGL Goes Here
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
if (!Aquarium::bitmap->LoadTGA(Aquarium::textures, "Data/NeHe.TGA")) // Jump To Texture Loading Routine ( NEW )
return FALSE; // If Texture Didn't Load Return FALSE
glEnable(GL_TEXTURE_2D);
return TRUE; // Initialization Went OK
}



I call this when i make a new instance of my aquarium class in the main.

Share this post


Link to post
Share on other sites
I always put a call to something like this in between OpenGL function calls.
void doCheckOpengl() {
GLenum error = glGetError();
if( error != GL_NO_ERROR ) {
std::string value ="???";
#define ERROR_VALUE(x) case x: value = #x; break
switch(error) {
ERROR_VALUE(GL_INVALID_ENUM);
ERROR_VALUE(GL_INVALID_VALUE);
ERROR_VALUE(GL_INVALID_OPERATION);
ERROR_VALUE(GL_STACK_OVERFLOW);
ERROR_VALUE(GL_STACK_UNDERFLOW);
ERROR_VALUE(GL_OUT_OF_MEMORY);
}
#undef ERROR_VALUE
std::cerr << "Opengl error: " << error << value << std::endl;
#ifdef _DEBUG
_asm { int 3 }
#endif
}
}

Share this post


Link to post
Share on other sites
Finaly i got it...

Thanks a lot guys.

For them who wanna know where the problem was. I made a new instance of the aquarium class outside of the main... so the init of the aquarium was not observed.

Such a stupid error ^^

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      627765
    • Total Posts
      2978983
  • Similar Content

    • By DelicateTreeFrog
      Hello! As an exercise for delving into modern OpenGL, I'm creating a simple .obj renderer. I want to support things like varying degrees of specularity, geometry opacity, things like that, on a per-material basis. Different materials can also have different textures. Basic .obj necessities. I've done this in old school OpenGL, but modern OpenGL has its own thing going on, and I'd like to conform as closely to the standards as possible so as to keep the program running correctly, and I'm hoping to avoid picking up bad habits this early on.
      Reading around on the OpenGL Wiki, one tip in particular really stands out to me on this page:
      For something like a renderer for .obj files, this sort of thing seems almost ideal, but according to the wiki, it's a bad idea. Interesting to note!
      So, here's what the plan is so far as far as loading goes:
      Set up a type for materials so that materials can be created and destroyed. They will contain things like diffuse color, diffuse texture, geometry opacity, and so on, for each material in the .mtl file. Since .obj files are conveniently split up by material, I can load different groups of vertices/normals/UVs and triangles into different blocks of data for different models. When it comes to the rendering, I get a bit lost. I can either:
      Between drawing triangle groups, call glUseProgram to use a different shader for that particular geometry (so a unique shader just for the material that is shared by this triangle group). or
      Between drawing triangle groups, call glUniform a few times to adjust different parameters within the "master shader", such as specularity, diffuse color, and geometry opacity. In both cases, I still have to call glBindTexture between drawing triangle groups in order to bind the diffuse texture used by the material, so there doesn't seem to be a way around having the CPU do *something* during the rendering process instead of letting the GPU do everything all at once.
      The second option here seems less cluttered, however. There are less shaders to keep up with while one "master shader" handles it all. I don't have to duplicate any code or compile multiple shaders. Arguably, I could always have the shader program for each material be embedded in the material itself, and be auto-generated upon loading the material from the .mtl file. But this still leads to constantly calling glUseProgram, much more than is probably necessary in order to properly render the .obj. There seem to be a number of differing opinions on if it's okay to use hundreds of shaders or if it's best to just use tens of shaders.
      So, ultimately, what is the "right" way to do this? Does using a "master shader" (or a few variants of one) bog down the system compared to using hundreds of shader programs each dedicated to their own corresponding materials? Keeping in mind that the "master shaders" would have to track these additional uniforms and potentially have numerous branches of ifs, it may be possible that the ifs will lead to additional and unnecessary processing. But would that more expensive than constantly calling glUseProgram to switch shaders, or storing the shaders to begin with?
      With all these angles to consider, it's difficult to come to a conclusion. Both possible methods work, and both seem rather convenient for their own reasons, but which is the most performant? Please help this beginner/dummy understand. Thank you!
    • By JJCDeveloper
      I want to make professional java 3d game with server program and database,packet handling for multiplayer and client-server communicating,maps rendering,models,and stuffs Which aspect of java can I learn and where can I learn java Lwjgl OpenGL rendering Like minecraft and world of tanks
    • By AyeRonTarpas
      A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

      -What I'm using:
          C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.  
      -Questions
      Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?  
    • By ferreiradaselva
      Both functions are available since 3.0, and I'm currently using `glMapBuffer()`, which works fine.
      But, I was wondering if anyone has experienced advantage in using `glMapBufferRange()`, which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
      Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
    • By xhcao
      Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness. 
  • Popular Now