Home » U++ Library support » U++ Library : Other (not classified elsewhere) » opengl & tekstures
opengl & tekstures [message #1853] |
Thu, 23 March 2006 13:21 |
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
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 |
|
I'm sure it is not connected with upp at all I use directx with upp and all textures are painted without any problem . There must be something with your code...
|
|
|
|
Re: opengl & tekstures [message #1888 is a reply to message #1886] |
Fri, 24 March 2006 23:01 |
|
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 #2435 is a reply to message #2433] |
Wed, 12 April 2006 16:55 |
|
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 #2714 is a reply to message #1853] |
Sat, 22 April 2006 12:05 |
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 #2977 is a reply to message #1853] |
Tue, 02 May 2006 16:26 |
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?
|
|
|
Goto Forum:
Current Time: Thu May 23 18:37:55 CEST 2024
Total time taken to generate the page: 0.02589 seconds
|