• Advertisement
Sign in to follow this  

OpenGL Textur Mapping problem

This topic is 3876 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 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
Advertisement
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
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By reenigne
      For those that don't know me. I am the individual who's two videos are listed here under setup for https://wiki.libsdl.org/Tutorials
      I also run grhmedia.com where I host the projects and code for the tutorials I have online.
      Recently, I received a notice from youtube they will be implementing their new policy in protecting video content as of which I won't be monetized till I meat there required number of viewers and views each month.

      Frankly, I'm pretty sick of youtube. I put up a video and someone else learns from it and puts up another video and because of the way youtube does their placement they end up with more views.
      Even guys that clearly post false information such as one individual who said GLEW 2.0 was broken because he didn't know how to compile it. He in short didn't know how to modify the script he used because he didn't understand make files and how the requirements of the compiler and library changes needed some different flags.

      At the end of the month when they implement this I will take down the content and host on my own server purely and it will be a paid system and or patreon. 

      I get my videos may be a bit dry, I generally figure people are there to learn how to do something and I rather not waste their time. 
      I used to also help people for free even those coming from the other videos. That won't be the case any more. I used to just take anyone emails and work with them my email is posted on the site.

      I don't expect to get the required number of subscribers in that time or increased views. Even if I did well it wouldn't take care of each reoccurring month.
      I figure this is simpler and I don't plan on putting some sort of exorbitant fee for a monthly subscription or the like.
      I was thinking on the lines of a few dollars 1,2, and 3 and the larger subscription gets you assistance with the content in the tutorials if needed that month.
      Maybe another fee if it is related but not directly in the content. 
      The fees would serve to cut down on the number of people who ask for help and maybe encourage some of the people to actually pay attention to what is said rather than do their own thing. That actually turns out to be 90% of the issues. I spent 6 hours helping one individual last week I must have asked him 20 times did you do exactly like I said in the video even pointed directly to the section. When he finally sent me a copy of the what he entered I knew then and there he had not. I circled it and I pointed out that wasn't what I said to do in the video. I didn't tell him what was wrong and how I knew that way he would go back and actually follow what it said to do. He then reported it worked. Yea, no kidding following directions works. But hey isn't alone and well its part of the learning process.

      So the point of this isn't to be a gripe session. I'm just looking for a bit of feed back. Do you think the fees are unreasonable?
      Should I keep the youtube channel and do just the fees with patreon or do you think locking the content to my site and require a subscription is an idea.

      I'm just looking at the fact it is unrealistic to think youtube/google will actually get stuff right or that youtube viewers will actually bother to start looking for more accurate videos. 
    • By Balma Alparisi
      i got error 1282 in my code.
      sf::ContextSettings settings; settings.majorVersion = 4; settings.minorVersion = 5; settings.attributeFlags = settings.Core; sf::Window window; window.create(sf::VideoMode(1600, 900), "Texture Unit Rectangle", sf::Style::Close, settings); window.setActive(true); window.setVerticalSyncEnabled(true); glewInit(); GLuint shaderProgram = createShaderProgram("FX/Rectangle.vss", "FX/Rectangle.fss"); float vertex[] = { -0.5f,0.5f,0.0f, 0.0f,0.0f, -0.5f,-0.5f,0.0f, 0.0f,1.0f, 0.5f,0.5f,0.0f, 1.0f,0.0f, 0.5,-0.5f,0.0f, 1.0f,1.0f, }; GLuint indices[] = { 0,1,2, 1,2,3, }; GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); GLuint vbo; glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW); GLuint ebo; glGenBuffers(1, &ebo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices,GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(float) * 5, (void*)0); glEnableVertexAttribArray(0); glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(float) * 5, (void*)(sizeof(float) * 3)); glEnableVertexAttribArray(1); GLuint texture[2]; glGenTextures(2, texture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); sf::Image* imageOne = new sf::Image; bool isImageOneLoaded = imageOne->loadFromFile("Texture/container.jpg"); if (isImageOneLoaded) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageOne->getSize().x, imageOne->getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageOne->getPixelsPtr()); glGenerateMipmap(GL_TEXTURE_2D); } delete imageOne; glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); sf::Image* imageTwo = new sf::Image; bool isImageTwoLoaded = imageTwo->loadFromFile("Texture/awesomeface.png"); if (isImageTwoLoaded) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageTwo->getSize().x, imageTwo->getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageTwo->getPixelsPtr()); glGenerateMipmap(GL_TEXTURE_2D); } delete imageTwo; glUniform1i(glGetUniformLocation(shaderProgram, "inTextureOne"), 0); glUniform1i(glGetUniformLocation(shaderProgram, "inTextureTwo"), 1); GLenum error = glGetError(); std::cout << error << std::endl; sf::Event event; bool isRunning = true; while (isRunning) { while (window.pollEvent(event)) { if (event.type == event.Closed) { isRunning = false; } } glClear(GL_COLOR_BUFFER_BIT); if (isImageOneLoaded && isImageTwoLoaded) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture[1]); glUseProgram(shaderProgram); } glBindVertexArray(vao); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr); glBindVertexArray(0); window.display(); } glDeleteVertexArrays(1, &vao); glDeleteBuffers(1, &vbo); glDeleteBuffers(1, &ebo); glDeleteProgram(shaderProgram); glDeleteTextures(2,texture); return 0; } and this is the vertex shader
      #version 450 core layout(location=0) in vec3 inPos; layout(location=1) in vec2 inTexCoord; out vec2 TexCoord; void main() { gl_Position=vec4(inPos,1.0); TexCoord=inTexCoord; } and the fragment shader
      #version 450 core in vec2 TexCoord; uniform sampler2D inTextureOne; uniform sampler2D inTextureTwo; out vec4 FragmentColor; void main() { FragmentColor=mix(texture(inTextureOne,TexCoord),texture(inTextureTwo,TexCoord),0.2); } I was expecting awesomeface.png on top of container.jpg

    • By khawk
      We've just released all of the source code for the NeHe OpenGL lessons on our Github page at https://github.com/gamedev-net/nehe-opengl. code - 43 total platforms, configurations, and languages are included.
      Now operated by GameDev.net, NeHe is located at http://nehe.gamedev.net where it has been a valuable resource for developers wanting to learn OpenGL and graphics programming.

      View full story
    • By TheChubu
      The Khronos™ Group, an open consortium of leading hardware and software companies, announces from the SIGGRAPH 2017 Conference the immediate public availability of the OpenGL® 4.6 specification. OpenGL 4.6 integrates the functionality of numerous ARB and EXT extensions created by Khronos members AMD, Intel, and NVIDIA into core, including the capability to ingest SPIR-V™ shaders.
      SPIR-V is a Khronos-defined standard intermediate language for parallel compute and graphics, which enables content creators to simplify their shader authoring and management pipelines while providing significant source shading language flexibility. OpenGL 4.6 adds support for ingesting SPIR-V shaders to the core specification, guaranteeing that SPIR-V shaders will be widely supported by OpenGL implementations.
      OpenGL 4.6 adds the functionality of these ARB extensions to OpenGL’s core specification:
      GL_ARB_gl_spirv and GL_ARB_spirv_extensions to standardize SPIR-V support for OpenGL GL_ARB_indirect_parameters and GL_ARB_shader_draw_parameters for reducing the CPU overhead associated with rendering batches of geometry GL_ARB_pipeline_statistics_query and GL_ARB_transform_feedback_overflow_querystandardize OpenGL support for features available in Direct3D GL_ARB_texture_filter_anisotropic (based on GL_EXT_texture_filter_anisotropic) brings previously IP encumbered functionality into OpenGL to improve the visual quality of textured scenes GL_ARB_polygon_offset_clamp (based on GL_EXT_polygon_offset_clamp) suppresses a common visual artifact known as a “light leak” associated with rendering shadows GL_ARB_shader_atomic_counter_ops and GL_ARB_shader_group_vote add shader intrinsics supported by all desktop vendors to improve functionality and performance GL_KHR_no_error reduces driver overhead by allowing the application to indicate that it expects error-free operation so errors need not be generated In addition to the above features being added to OpenGL 4.6, the following are being released as extensions:
      GL_KHR_parallel_shader_compile allows applications to launch multiple shader compile threads to improve shader compile throughput WGL_ARB_create_context_no_error and GXL_ARB_create_context_no_error allow no error contexts to be created with WGL or GLX that support the GL_KHR_no_error extension “I’m proud to announce OpenGL 4.6 as the most feature-rich version of OpenGL yet. We've brought together the most popular, widely-supported extensions into a new core specification to give OpenGL developers and end users an improved baseline feature set. This includes resolving previous intellectual property roadblocks to bringing anisotropic texture filtering and polygon offset clamping into the core specification to enable widespread implementation and usage,” said Piers Daniell, chair of the OpenGL Working Group at Khronos. “The OpenGL working group will continue to respond to market needs and work with GPU vendors to ensure OpenGL remains a viable and evolving graphics API for all its customers and users across many vital industries.“
      The OpenGL 4.6 specification can be found at https://khronos.org/registry/OpenGL/index_gl.php. The GLSL to SPIR-V compiler glslang has been updated with GLSL 4.60 support, and can be found at https://github.com/KhronosGroup/glslang.
      Sophisticated graphics applications will also benefit from a set of newly released extensions for both OpenGL and OpenGL ES to enable interoperability with Vulkan and Direct3D. These extensions are named:
      GL_EXT_memory_object GL_EXT_memory_object_fd GL_EXT_memory_object_win32 GL_EXT_semaphore GL_EXT_semaphore_fd GL_EXT_semaphore_win32 GL_EXT_win32_keyed_mutex They can be found at: https://khronos.org/registry/OpenGL/index_gl.php
      Industry Support for OpenGL 4.6
      “With OpenGL 4.6 our customers have an improved set of core features available on our full range of OpenGL 4.x capable GPUs. These features provide improved rendering quality, performance and functionality. As the graphics industry’s most popular API, we fully support OpenGL and will continue to work closely with the Khronos Group on the development of new OpenGL specifications and extensions for our customers. NVIDIA has released beta OpenGL 4.6 drivers today at https://developer.nvidia.com/opengl-driver so developers can use these new features right away,” said Bob Pette, vice president, Professional Graphics at NVIDIA.
      "OpenGL 4.6 will be the first OpenGL release where conformant open source implementations based on the Mesa project will be deliverable in a reasonable timeframe after release. The open sourcing of the OpenGL conformance test suite and ongoing work between Khronos and X.org will also allow for non-vendor led open source implementations to achieve conformance in the near future," said David Airlie, senior principal engineer at Red Hat, and developer on Mesa/X.org projects.

      View full story
    • By _OskaR
      Hi,
      I have an OpenGL application but without possibility to wite own shaders.
      I need to perform small VS modification - is possible to do it in an alternative way? Do we have apps or driver modifictions which will catch the shader sent to GPU and override it?
  • Advertisement