Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » opengl & tekstures
opengl & tekstures [message #1853] Thu, 23 March 2006 13:21 Go to next message
barpas is currently offline  barpas
Messages: 13
Registered: March 2006
Location: Poland
Promising Member
has anybody working upp code with opengl using textrue ???
i tray to do it many times eg with nehe tutorials but it's not working ...

eg. i tray convert to upp 6 lesson for neht tutorial - everything semms to by ok file is open textrure is done but qube is white (non textured)

i don't understend

i use functions likie that:

AUX_RGBImageRec* OpenGL::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
}

int OpenGL::LoadGLTextures()									// 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/to.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
}





in GLPaint() metod:



void OpenGL::GLPaint()
{
	StdView();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
	glLoadIdentity();									// Reset The View
//	glRotatef(lookupdown,0.0f,0,0);
//glRotatef(sceneroty,0,1.0f,0);
glBindTexture(GL_TEXTURE_2D, texture[0]);
	glBegin(GL_QUADS);									// Draw A Quad
	//	glColor3f(0.0f,1.0f,0.0f);						// Set The Color To Green
	glNormal3f( 0.0f, 0.0f, 1.0f); 
		glTexCoord2f(1.0f, 0.0f);glVertex3f( szerokosc/2, -1.0f,-dlugosc/2);					// Top Right Of The Quad (Top)
		glTexCoord2f(1.0f, 0.0f);glVertex3f(-szerokosc/2, -1.0f,-dlugosc/2);					// Top Left Of The Quad (Top)
		glTexCoord2f(1.0f, 0.0f);glVertex3f(-szerokosc/2, -1.0f, dlugosc/2);					// Bottom Left Of The Quad (Top)
		glTexCoord2f(1.0f, 0.0f);glVertex3f( szerokosc/2, -1.0f, dlugosc/2);					// Bottom Right Of The Quad (Top)
...
	glEnd();
	
};



of course i use
#include <GL/glaux.h>


help me please - what i'm dooing wrong????


Re: opengl & tekstures [message #1863 is a reply to message #1853] Fri, 24 March 2006 08:45 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

I'm sure it is not connected with upp at all Smile I use directx with upp and all textures are painted without any problem . There must be something with your code...
Re: opengl & tekstures [message #1886 is a reply to message #1853] Fri, 24 March 2006 22:53 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Regarding textures. My guess that you placed your bmp files somewhere out of reach for you exe...
And because the lesson example is programmed in a very stupid way you are not informed about it Smile

Advice No1. - in IDE "Build" menu open "Output Directory" and move or copy all *.bmp etc. files which you are using in your app. In that case, you can use e.g LoadBMP("nehe.bmp") etc. or use full paths to files e.g LoadBMP("D:\data\nehe.bmp")

Advice No2. - put PromptOK("step1"); as guards to check if your program came where you expected.
e.g

       if (File)                                       // Does The File Exist?
        {
                fclose(File);
                PromptOK("really opening DIB");                          // Close The Handle
                return auxDIBImageLoad(Filename);       // Load The Bitmap And Return A Pointer
        }
Re: opengl & tekstures [message #1888 is a reply to message #1886] Fri, 24 March 2006 23:01 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Actually, more clever way would be like this
AUX_RGBImageRec* OpenGL::LoadBMP(char *Filename)                // Loads A Bitmap Image
{
        FILE *File=NULL;                                // File Handle

        if (!Filename)                                  // Make Sure A Filename Was Given
        {
PromptOK("Where is your filename?!" );
                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
        }
        else PromptOK("Couldn't load "+ AsString(Filename) );
        return NULL;                                    // If Load Failed Return NULL
}

[Updated on: Fri, 24 March 2006 23:02]

Report message to a moderator

Re: opengl & tekstures [message #1891 is a reply to message #1886] Fri, 24 March 2006 23:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Fri, 24 March 2006 16:53

Regarding textures. My guess that you placed your bmp files somewhere out of reach for you exe...



BTW, exactly because of this, there is nice "hack" function GetDataFile function - when your .exe is started from TheIDE, GetDataFile("xxx") will return the full path to "xxx.x" inside your main package.

That way you can store you graphics files together with sources.

When started outside TheIDE (final version), GetDataFile returns the file from the same directory as is .exe places (very likely arrangement for your production files).

Mirek
Re: opengl & tekstures [message #1898 is a reply to message #1891] Sat, 25 March 2006 01:22 Go to previous messageGo to next message
barpas is currently offline  barpas
Messages: 13
Registered: March 2006
Location: Poland
Promising Member
i'm sory but its not resolving my problem - i was thinging abaut it and debug it to look if i have a good pointer ...
pointer was good,
booth functions returns good status ...
but platform was white
(now it is colored)

if you don't belive me there is code of that in robot.cpp (topic abaut arrayctrl & edit) - i didnt sent a picture but you can use anything to test it

i think so eg the green "floor" should by textrued but isn't Sad

i don't undestend wby - i do the same in mvc and working good
maybe i make misteak semewhere but maybe glaux don't work ok wiht upp???

Bartek
Re: opengl & tekstures [message #2370 is a reply to message #1853] Mon, 10 April 2006 01:35 Go to previous messageGo to next message
lindquist is currently offline  lindquist
Messages: 33
Registered: March 2006
Location: Denmark
Member
I'm not sure if you solved it or not, but you may just be missing a
glEnable(GL_TEXTURE_2D);
call.

The default GLCtrl is very minimal, and the default OpenGL state for GL_TEXTURE_2D is disabled.
Re: opengl & tekstures [message #2433 is a reply to message #2370] Wed, 12 April 2006 16:36 Go to previous messageGo to next message
barpas is currently offline  barpas
Messages: 13
Registered: March 2006
Location: Poland
Promising Member
i have it in my code...
and problmem is not resolved ...
is here anybody who made upp application with opengl using textures ???
Re: opengl & tekstures [message #2435 is a reply to message #2433] Wed, 12 April 2006 16:55 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
barpas wrote on Wed, 12 April 2006 15:36

i have it in my code...
and problmem is not resolved ...
is here anybody who made upp application with opengl using textures ???


I was trying your example and many others for 2 days... with all possible options. Then lost patience. Glut works but not U++...

I guess something wrong with OpenGLCtrl pixel format? descriptor?
or maybe some more inits required?

Because OpenGL returns errors at the very early stages of initialization if you check with its functions...
Just my guess.

[Updated on: Wed, 12 April 2006 16:56]

Report message to a moderator

Re: opengl & tekstures [message #2436 is a reply to message #2435] Wed, 12 April 2006 17:02 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
or could be buffers? I had found later some info on the net, but haven't tested...
Re: opengl & tekstures [message #2714 is a reply to message #1853] Sat, 22 April 2006 12:05 Go to previous messageGo to next message
lindquist is currently offline  lindquist
Messages: 33
Registered: March 2006
Location: Denmark
Member
I'm successfully using the GLCtrl with texturing.

Image img = PngEncoder::New()->LoadImageFile("texture/test.png");
PixelArray pix = ImageToPixelArray(img);

// pixelformat
GLuint chan,fmt,id;
switch (pix.GetBPP())
{
case 24:
	chan = 3;
	fmt = GL_RGB;
	break;

case 32:
	chan = 4;
	fmt = GL_RGBA;
	break;

default:
	Exclamation("Unsupported texture BPP ("+FormatInt(pix.GetBPP())+")");
	return false;
}

glGenTextures(1,&id);
glBindTexture(GL_TEXTURE_2D, id);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

gluBuild2DMipmaps(GL_TEXTURE_2D, chan, pix.GetWidth(), pix.GetHeight(), fmt, GL_UNSIGNED_BYTE, pix.Begin());
return true;


My GLCtrl is slightly modified. First I'm using GLee for easy access to extensions, and second, I have the 'wglMakeCurrent(NULL, NULL);' line commented in GLCtrl::WindowProc.

I also inserted 'wglMakeCurrent(hDC, hRC);' at the end of 'GLCtrl::OpenGL'.

At first I had some issues, but it turned out to be my min filter that was LINEAR_MIPMAP_LINEAR while I used glTexImage2D...

I hope this is of help.

[Updated on: Sat, 22 April 2006 12:12]

Report message to a moderator

Re: opengl & tekstures [message #2947 is a reply to message #2714] Mon, 01 May 2006 10:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
BTW, should I change GLCtrl? I must admit that this is area that is completely out of my knowledge, so any contributions here are much welcome!

Mirek
Re: opengl & tekstures [message #2977 is a reply to message #1853] Tue, 02 May 2006 16:26 Go to previous message
lindquist is currently offline  lindquist
Messages: 33
Registered: March 2006
Location: Denmark
Member
I would say yes. Make those changes.

The problem with not having them in means that OpenGL calls can only be made inside the GLPaint method.

As things like loading textures etc often happens somewhere else (not in the render code) this is somewhat and obstacle.

The problem with my simple approach is that if you're using multiple GLCtrls then we would need a method to activate the content we want to work on.

A MakeActive member might be a good idea. Or something else... For me, the approach I took is just fine as I only have one GL context.
And I just want to write GL code and expect it to work on that context.

P.S the texture code I posted only sort of works. the correct pixel format seems to be GL_BGR/GL_BGRA, using these the colours are correct. Tho it might still be flipped, as IIRC OpenGL expects a bottom-left origin.

Is ultimate++ top-left? and is the bgra format consistent? or do I need to do some more checking?
Previous Topic: uvs wishes
Next Topic: namespace upp
Goto Forum:
  


Current Time: Sun Apr 28 17:40:51 CEST 2024

Total time taken to generate the page: 0.02119 seconds