View Full Version : OpenGL Texture not displaying - my first class.
Jones
2006.07.08, 02:45 PM
Well, I just started messing around with OOP classes, and so far I've found them to be pretty cool. As my first, I figured I'd start with something relatively simple: A form of SDL_Surface, but for OpenGL. It uses DevIL and OpenGL. Unfortunatly, my texture does not appear.
I've actually posted a thread about this over at gameDev, but then I realized. Oh wait... what am I doing? It's the mac users that are the smart ones, I'll ask them. ;)
Here's the other thread, for reference. (http://www.gamedev.net/community/forums/topic.asp?topic_id=402506)
What I've tried:
- Binding the texture directly from IL, instead of from my class variables. (When drawing.)
- Inserting little warning tags after every action. (Showed no problems.)
- Swapping up the vertex ordering of the texture grabbing.
No luck, anyhow. Here's my class:
(Feel free to tell me how useless it is! :p )
#include <cstdlib>
#include <cstring>
#include "OpenGL/gl.h"
#include "OpenGL/glu.h"
#include "IL/il.h"
#include "IL/ilu.h"
#include "IL/ilut.h"
using namespace std;
class glSurface {
protected:
GLint components;
GLsizei width;
GLsizei height;
GLenum format;
GLvoid *pixels;
ILuint image_IL;
GLuint texture_GL;
int x;
int y;
int firstDraw;
public:
glSurface();
int Open(char *);
void Position(int, int);
void Draw();
};
glSurface::glSurface() {
ilGenImages(1, &image_IL);
glGenTextures(1, &texture_GL);
firstDraw = 1;
}
int glSurface::Open(char filename[]) {
ILint open_currentBound_IL = ilGetInteger(IL_CUR_IMAGE);
ILboolean open_success_IL;
ilBindImage(image_IL);
open_success_IL = ilLoadImage(filename);
if (open_success_IL == IL_FALSE) {
ilBindImage(open_currentBound_IL);
cout << "Problem!" << endl;
return(-1);
}
components = ilGetInteger(IL_IMAGE_BPP);
width = ilGetInteger(IL_IMAGE_WIDTH);
height = ilGetInteger(IL_IMAGE_HEIGHT);
format = ilGetInteger(IL_IMAGE_FORMAT);
pixels = ilGetData();
ilBindImage(open_currentBound_IL);
return(0);
}
void glSurface::Position(int tx, int ty) {
x = tx;
y = ty;
}
void glSurface::Draw() {
glBindTexture(GL_TEXTURE_2D, texture_GL);
if (firstDraw = 1) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, components, width, height, 0, format, GL_UNSIGNED_BYTE, pixels);
firstDraw = 0;
}
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex2i(x, y);
glTexCoord2i(0, 1); glVertex2i(x + width, y);
glTexCoord2i(1, 1); glVertex2i(x + width, y + height);
glTexCoord2i(1, 0); glVertex2i(x, y + width);
glEnd();
}
Thanks for any help you can give!
Greywhind
2006.07.08, 03:24 PM
I don't know DevIL, so your code might already do this depending on DevIL's setup of surfaces. But remember that OpenGL (afaik) can't load non-power-of-two textures. That might be your problem.
On another note, I am using SDL for loading of OpenGL textures, and loving it. Took some doing to set up, but there's a tutorial (GLtest) in the SDL source code that shows exactly how to do it. If you use SDL at some point instead of DevIL, try it out.
Hope you solve your problem - I hate getting white squares or nothing instead of textures.
Fenris
2006.07.08, 05:49 PM
Everything looks OK, but when you say that the texture doesn't appear - what happens? White square, or nothing? Also, is GL_TEXTURE_2D enabled?
Jones
2006.07.08, 11:10 PM
I don't know DevIL, so your code might already do this depending on DevIL's setup of surfaces. But remember that OpenGL (afaik) can't load non-power-of-two textures. That might be your problem.
That must be the third or forth time I've forgotten that rule. *sigh*
Thanks, my problem should be solved now.
*1 minute later*
Yeah, it's solved... sorta. One problem remains though.
My colors... check out the original tiff:
http://homepage.mac.com/gareth.cross/copter_base.tif
Now, after load:
http://homepage.mac.com/gareth.cross/copter_wtf.png
Ignore the rotation, that's actually just a texpos mis-type. But why is it Pink? I'm guessing it's because of some sort of byte ordering error. It's a tif, with transparency, and DevIL should be passing the right format. This *might* be another pixen error, but I viewed it in photoshop and it seemed fine.
backslash
2006.07.09, 07:38 AM
The dark blue windows becoming light yellow suggests that you are inverting the RGB channels, although the green/pink area maintains its shadows so this may not be quite right. It could be a little endian/big endian error with the RGB values. Also check you are reading the correct pixel format (not mixing up RGBA with ARGB or something), although I think you are OK on that one.
Jones
2006.07.09, 12:20 PM
The dark blue windows becoming light yellow suggests that you are inverting the RGB channels, although the green/pink area maintains its shadows so this may not be quite right. It could be a little endian/big endian error with the RGB values. Also check you are reading the correct pixel format (not mixing up RGBA with ARGB or something), although I think you are OK on that one.
That's what I was thinking... might it be my "type" in glTexImage2D? It's set at GL_UNSIGNED_BYTE, perhaps GL_BITMAP or another choice could help...
I also can't get it to be oriented correctly, If I assume that the top-left corner is 0,0 of my texture it looks like the above picture. If I assume that bottom-left corner is 0,0... it's upside down. :???: I'm gonna take a wild guess and try drawing the from the right corners.
Using DevIL, I tried forcing the image to be RGBA with:
ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
But it remained tinted pink and yellow.
EDIT: Trying to make it any other type results in a type 4 crash.
EDIT 2: I tried making GL use ONLY GL_RGBA isntead of what DevIL gave it, like this:
glTexImage2D(GL_TEXTURE_2D, 0, components, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
It's still pink. :( Grr. I'm gonna try another format besides tif.
EDIT 3: Make another go, but with a gif... it just doesn't even draw the quad now! *smashes head against keyboard.* I mean come-on, the image only has like 4 little colors! No blending at all! Argh!
EDIT 4: Well, just noticed something... even if I rotated the image, or changed where it's drawn from, it'll still be backwards. This must be a byte ordering thing, with my tifs and DevIL. Pity, that's the only format I can export too that supports transparency. That and gif, which doesn't load.
backslash
2006.07.09, 07:34 PM
Personally, I've always used PNGs. Libpng may not be the easiest library in the world, but the example code is quite good, and you only really have to write this stuff once. Don't feel constrained by only being able to export TIFFs - Preview can convert to many formats (including PNG), and there are plenty of free tools out there.
Anyway...
For your texture coordinates, you should have (0,0) in the top left and (1,0) in the top right. You appear to have the x and y coordinates mixed up between the texture coords and the the polygon coords in the code above. Also, remember that if (0,0) is the bottom left corner of the screen then you need to use y-height for the lower corners. I think this is why you are seeing it backwards - you are actually looking at the back of it.
Fenris
2006.07.10, 03:51 AM
Are you on an Intel or PPC mac?
Jones
2006.07.27, 02:53 PM
Wow... it took me a while to get back to this thread.
Anyways:
I'm on PPC, too cheap for an intel one yet. :)
Anyways, I've got a problem again similar to this one, so I put it in this thread.
I've tried out libpng (again, after leaving it for DevIL) and I wrote a C++ class for using it with OpenGL. It supports error codes, arbitrary sized textures and stuff too. Here's the source:
#include <cstdlib>
#include <fstream>
#include "OpenGL/gl.h"
#include "OpenGL/glu.h"
#include <png.h>
#define PNG_NO_FILE 89224
#define PNG_BAD_FILE 71120
#define PNG_STRUCT_ERR 22398
#define PNG_LIB_ERR 10893
#define PNG_NO_MEMORY 62009
#define PNG_NO_ERR 55872
#define PNG_BUF_FULL 01512
#define PNG_BUF_EMPTY 11943
#define PNG_BAD_TEX 99124
using namespace std;
class PNG {
protected:
FILE *p_stream;
png_structp p_pngPTR;
png_infop p_infoPTR;
png_bytepp p_rowPointers;
unsigned char p_sig[8];
unsigned int p_cur_error;
bool p_imageLoaded;
public:
GLenum p_targArgs;
GLenum p_colArgs;
unsigned char *p_image;
unsigned int p_depth;
unsigned int p_colorType;
unsigned long p_width;
unsigned long p_height;
unsigned int p_rowbytes;
PNG();
bool Open(char*);
bool Flush();
bool Texture(GLuint);
};
/* Constructor, sets some pointers to null. */
PNG::PNG() {
p_image = NULL;
p_rowPointers = NULL;
p_imageLoaded = FALSE;
p_cur_error = PNG_NO_ERR;
}
/* Open a png image. */
bool PNG::Open(char *p_file) {
if (p_imageLoaded == TRUE) {
p_cur_error = PNG_BUF_FULL;
return(FALSE);
}
/* Open the file. */
p_stream = fopen(p_file, "rb");
if (!p_stream) {
p_cur_error = PNG_NO_FILE;
return(FALSE);
}
/* Read the file signature, and validate it. */
fread(p_sig, 1, 8, p_stream);
if (!png_check_sig((unsigned char *)p_sig, 8)) {
p_cur_error = PNG_BAD_FILE;
fclose(p_stream);
return(FALSE);
}
/* Create the png struct. */
p_pngPTR = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!p_pngPTR) {
fclose(p_stream);
p_cur_error = PNG_STRUCT_ERR;
return(FALSE);
}
/* Create the info struct. */
p_infoPTR = png_create_info_struct(p_pngPTR);
if (!p_infoPTR) {
png_destroy_read_struct(&p_pngPTR, (png_infopp) NULL, (png_infopp) NULL);
fclose(p_stream);
p_cur_error = PNG_STRUCT_ERR;
return(FALSE);
}
/* Handles libpng errors. */
if (setjmp(png_jmpbuf(p_pngPTR))) {
png_destroy_read_struct(&p_pngPTR, &p_infoPTR, NULL);
fclose(p_stream);
p_cur_error = PNG_LIB_ERR;
return(FALSE);
}
/* Store our file stream pointer. */
png_init_io(p_pngPTR, p_stream);
/* Tell libpng not to look for the file signature. */
png_set_sig_bytes(p_pngPTR, 8);
/* Get everything up to actual image data. */
png_read_info(p_pngPTR, p_infoPTR);
/* Take in the info, stick it in variables. */
png_get_IHDR(p_pngPTR, p_infoPTR, &p_width, &p_height,
(int*)&p_depth, (int*)&p_colorType, NULL, NULL, NULL);
/* Convert some stuff, if we have to. */
if (p_colorType & PNG_COLOR_MASK_ALPHA) {
png_set_strip_alpha(p_pngPTR);
}
if (p_depth > 8) {
png_set_strip_16(p_pngPTR);
}
if (p_colorType == PNG_COLOR_TYPE_GRAY ||
p_colorType == PNG_COLOR_TYPE_GRAY_ALPHA) {
png_set_gray_to_rgb(p_pngPTR);
}
if (p_colorType == PNG_COLOR_TYPE_PALETTE) {
png_set_palette_to_rgb(p_pngPTR);
}
/* Update the info. */
png_read_update_info(p_pngPTR, p_infoPTR);
/* Number of rowsize, in bytes. */
p_rowbytes = png_get_rowbytes(p_pngPTR, p_infoPTR);
/* Allocate memory for pixel data. */
if ((p_image = (unsigned char*)malloc(p_rowbytes * p_height)) == NULL) {
png_destroy_read_struct(&p_pngPTR, &p_infoPTR, NULL);
p_cur_error = PNG_NO_MEMORY;
return(FALSE);
}
if ((p_rowPointers = (png_bytepp)malloc(p_height * sizeof(png_bytepp))) == NULL) {
png_destroy_read_struct(&p_pngPTR, &p_infoPTR, NULL);
free(p_image);
p_image = NULL;
p_cur_error = PNG_NO_MEMORY;
return(FALSE);
}
/* Correct the row pointer offsets. */
for (int p_counter = 0; p_counter < p_height; p_counter++) {
p_rowPointers[p_height - 1 - p_counter] = p_image + p_counter * p_rowbytes;
}
/* Read in the image. */
png_read_image(p_pngPTR, p_rowPointers);
free(p_rowPointers);
fclose(p_stream);
/* Is it arbitrary, and non power of two? */
if (p_width & (p_width * -1) != 0) {
p_targArgs = GL_TEXTURE_RECTANGLE_ARB;
}
else if (p_height & (p_height * -1) != 0) {
p_targArgs = GL_TEXTURE_RECTANGLE_ARB;
}
else {
p_targArgs = GL_TEXTURE_2D;
}
/* Check COLOR settings... */
if (p_colorType == PNG_COLOR_TYPE_RGB_ALPHA) {
p_colArgs = GL_RGBA;
}
else if (p_colorType == PNG_COLOR_TYPE_RGB) {
p_colArgs = GL_RGB;
}
p_cur_error = PNG_NO_ERR;
p_imageLoaded = TRUE;
return(TRUE);
}
/* Clean out PNG data. */
bool PNG::Flush() {
if (p_imageLoaded == FALSE) {
p_cur_error = PNG_BUF_EMPTY;
return(FALSE);
}
png_destroy_read_struct(&p_pngPTR, &p_infoPTR, NULL);
free(p_image);
p_image = NULL;
p_imageLoaded = FALSE;
p_cur_error = PNG_NO_ERR;
return(TRUE);
}
/* Bind a gl texture. */
bool PNG::Texture(GLuint p_tex) {
/* Is the image loaded? */
if (p_imageLoaded == FALSE) {
p_cur_error = PNG_BUF_EMPTY;
return(FALSE);
}
/* Are it's sizes valid? */
if ((p_width <= 0) || (p_height <= 0)) {
p_cur_error = PNG_BAD_TEX;
return(FALSE);
}
/* Make a texture, use the ARB/2D values and color types. */
glBindTexture(p_targArgs, p_tex);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(p_targArgs, 0, p_colArgs, p_width, p_height,
0, p_colArgs, GL_UNSIGNED_BYTE, p_image);
p_cur_error = PNG_NO_ERR;
return(TRUE);
}
Here's my main file (simple testing one):
#include <cstdlib>
#include <cstring>
#include <cmath>
#include "GLUT/glut.h"
#include "OpenGL/gl.h"
#include "OpenGL/glu.h"
#include "PNG_class.h"
using namespace std;
PNG myPicture;
GLuint hello;
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
myPicture.Open("/hello.png");
glGenTextures(1, &hello);
myPicture.Texture(hello);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glLoadIdentity();
glBindTexture(myPicture.p_targArgs, hello);
glTranslated(0, 0, -3);
glBegin(GL_QUADS);
glTexCoord2i(0,0);
glVertex3i(-1, 1, 0);
glTexCoord2i(1,0);
glVertex3i(1, 1, 0);
glTexCoord2i(1,1);
glVertex3i(1, -1, 0);
glTexCoord2i(0,1);
glVertex3i(-1, -1, 0);
glEnd();
glFlush();
}
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(320, 240);
glutInitWindowPosition(100, 100);
glutCreateWindow("OpenGL");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return(0);
}
But my quad is still white... :blink:
Wait... *thought* shouldn't I convert the signature for Big-Endian support? :sneaky:
I'll try that.
Thanks for any other plausible problems/solutions you can offer!
EDIT: Nope, sigs are chars... not a good solution.
akb825
2006.07.27, 03:10 PM
I know I'm a little late (didn't see this thread before), but when using DevIL, instead of using GL_RGBA in glTexImage2D(GL_TEXTURE_2D, 0, components, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); you probably should have used GL_BGRA. (for inverted blue and red channels)
For your libpng demo, is the texture a 2D texture or rectangular texture? You enable both GL_TEXTURE_2D and GL_TEXTURE_RECTANGLE_ARB, and I believe GL_TEXTURE_RECTANGLE_ARB takes precedence. If it's really a 2D texture, it won't display correctly.
BTW, you multiply by -1 to negate some numbers there: the unary - sign works. For example, this would be valid:
p_height & -p_height != 0
It won't make much of a difference, but it would take up a few less cycles. ;) (well, assuming you have optimizations turned on, it actually likely be optimized out. :p)
Jones
2006.07.27, 03:35 PM
I know I'm a little late (didn't see this thread before), but when using DevIL, instead of using GL_RGBA in glTexImage2D(GL_TEXTURE_2D, 0, components, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); you probably should have used GL_BGRA. (for inverted blue and red channels)
For your libpng demo, is the texture a 2D texture or rectangular texture? You enable both GL_TEXTURE_2D and GL_TEXTURE_RECTANGLE_ARB, and I believe GL_TEXTURE_RECTANGLE_ARB takes precedence. If it's really a 2D texture, it won't display correctly.
BTW, you multiply by -1 to negate some numbers there: the unary - sign works. For example, this would be valid:
p_height & -p_height != 0
It won't make much of a difference, but it would take up a few less cycles. ;) (well, assuming you have optimizations turned on, it actually likely be optimized out. :p)
Would it really? I've always done it * -1 because it seemed to be more... correct. Dunno why. :sneaky:
I enable both ARB and 2D because the class can handle both, and needs to have both enabled. I'll try removing one...
OneSadCookie
2006.07.27, 06:20 PM
If GL_TEXTURE_RECTANGLE_ARB is enabled, GL ignores whether GL_TEXTURE_2D is enabled (GL_TEXTURE_RECTANGLE_ARB takes precedence). Basically, it never makes sense to have more than one enabled at once.
arekkusu
2006.07.27, 08:05 PM
...on the same texture unit.
Jones
2006.07.27, 10:22 PM
Enabled just 2D (the one I'd need for my test picture), but nothing appears yet. This is strange, and I'm willing to bet it's something really stupid and simple I've completely missed. :p
akb825
2006.07.28, 03:23 AM
BTW, did you check your error values? Perhaps you just didn't successfully open the texture.
Jones
2006.07.28, 03:50 PM
BTW, did you check your error values? Perhaps you just didn't successfully open the texture.
That's what I put them there for, but I didn't use them. Heh. Silly me.
I'll try that.
Jones
2006.07.28, 04:04 PM
Well, I stuck this in my init()...
unsigned int foo;
bool uhoh = myPicture.Open("/hello.png");
if (!uhoh) {
foo = myPicture.GetErr();
}
Guess what I get back... 0.
Uh... that's not supposed to happen. :blink: Upon creation, the default error is PNG_NO_ERR which has some large value in it, can't remember what off the top of my head. Maybe it's not constructing correctly, the myPicture value I mean.
unknown
2006.07.28, 05:20 PM
Are you saying that the function 'myPicture.Open' should return PNG_NO_ERR on success?
If so you should store the return value in the same type of variable as the function returns and check for PNG_NO_ERR or change function call line to:
bool error = (myPicture.Open("/hello.png") != PNG_NO_ERR);
and change if (!uhoh) { to if (error) {
akb825
2006.07.28, 05:21 PM
Assuming you didn't mess up your GetError function (you don't show it in the source that you provided), that is certainly interesting.
BTW, as a comment, your error codes are.... interesting. They are all in decimal, except for one which is in octal. For arbitrary numbers like that, I suggest either using hex or just using an enum. If you need it to start at a certain number then follow afterwards, you can just set the first one then list the following ones. If it just doesn't matter, you can leave it to 0 - (number - 1).
Jones
2006.07.28, 09:01 PM
Are you saying that the function 'myPicture.Open' should return PNG_NO_ERR on success?
If so you should store the return value in the same type of variable as the function returns and check for PNG_NO_ERR or change function call line to:
bool error = (myPicture.Open("/hello.png") != PNG_NO_ERR);
and change if (!uhoh) { to if (error) {
No, my classes (I write this into all of them) always have their own error signatures, that you can check at any time. The "error buffer", an unsigned int, is updated every function call. If a function is successful, (in this case) PNG_NO_ERR is written to the buffer.
The getErr function just returns the value of the int in the buffer. It is NEVER 0.
@akb825, do you mean that those numbers might be returning as 0 because they're invalid, for some/whatever reason? I thought for a second maybe they were too long, but ints can hold that much data, I think.
Whenever I try to declare "enums" my compiler just throws a "no prior declaration" error. *shrug* I prefer ints anyway, easier to understand what's actually in them.
akb825
2006.07.28, 09:34 PM
No, they will work, it's just not easy to read, and seems rather arbitrary. In this case, I would make an enum like this:
enum {PNG_NO_ERR, PNG_NO_FILE, PNG_BAD_FILE, PNG_STRUCT_ERR, PNG_LIB_ERR, PNG_NO_MEMORY, PNG_BUF_FULL, PNG_BUF_EMPTY, PNG_BAD_TEX};
Note that I put the PNG_NO_ERROR first. Since it's special in the fact that it's the only one without an error, I gave it the special value of 0.
Jones
2006.07.28, 10:26 PM
No, they will work, it's just not easy to read, and seems rather arbitrary. In this case, I would make an enum like this:
enum {PNG_NO_ERR, PNG_NO_FILE, PNG_BAD_FILE, PNG_STRUCT_ERR, PNG_LIB_ERR, PNG_NO_MEMORY, PNG_BUF_FULL, PNG_BUF_EMPTY, PNG_BAD_TEX};
Note that I put the PNG_NO_ERROR first. Since it's special in the fact that it's the only one without an error, I gave it the special value of 0.
So, the order things are in in an enum list is there value?
In relation to my image problem:
I'm gonna take a wild guess and say that the constructor doesn't even run properly, which results in the error buffer being badly set...
Either that, or the conversion of a #define number being changed to an int. I'll try const numbers.
EDIT:
Uh oh, changed to const unsigned ints, and I still get zero...
My C++ is broken, can I borrow yours for a while? ;)
akb825
2006.07.28, 11:27 PM
The order of the values in the enum is their value, but you can assign values to each with =. If you assign a value to one of the items, the following will count up from that value.
To see if your constructor is being called correctly, put in print statements. Then, if that's being called, put print statements in your open method and see how far things go. Believe me, print statements are a very powerful tool when you're debugging, since they make it easy to see if you get somewhere, or how values change.
Jones
2006.07.29, 12:16 AM
The order of the values in the enum is their value, but you can assign values to each with =. If you assign a value to one of the items, the following will count up from that value.
To see if your constructor is being called correctly, put in print statements. Then, if that's being called, put print statements in your open method and see how far things go. Believe me, print statements are a very powerful tool when you're debugging, since they make it easy to see if you get somewhere, or how values change.
Latest version of xCode does not print out anything from classes, or class functions. It doesn't even write them to logs, when debugging. Don't know why, or how to fix it. :(
class joe {
joe();
};
joe::joe() {
cout << "Hello, World!" << endl;
int main() {
joe myJoe;
myJoe.joe;
}
}
Would return nothing. :\
Jones
2006.07.29, 01:24 PM
I went back and tried DevIL again, and funnily enough... it didn't crash this time, but it still displays nothing... (on the quad).
It's funny, sometimes this stuff works, and sometimes it doesn't... I'm wondering what's going on here. I've got to track down my original project with this problem...
Jones
2006.07.29, 02:33 PM
Little update on my attempts to get this to work:
It's returning zero because, the function returns true and works, so the error is not processed. *woops duh*
To get around xCodes block thingy, on couts, I inserted a tempcheck number in my class that would be == to 99 if no error and a number from 0 to 6 if there was an error at the stage indicated by that number. I got 99 back. The image opens fine, so it's got to be a display error.
Here's some info on the test image:
-128 * 128 (GL_TEXTURE_2D)
-Made with photoshop.
-No interlacing.
Anyways, the error is either in the function that builds a texture with the data, or when I bind it and display it.
:\
I then asked my init function to spit out the color and target arguments I had gotten from libpng, the ones that are passed to OpenGL. Here they are:
Color: 6407 (No idea what this indicates... probably GL_RGB, or GL_BGR).
Target: 3553 (Either GL_TEXTURE_2D, or GL_TEXTURE_RECTANGLE_ARB).
So I dug around in the gl.h header, and found out that this is equal to GL_TEXTURE_2D: 0x0DE1. I couldn't find GL_TEXTURE_RECTANGLE_ARB in that file. But it shouldn't be called anyway, in this case.
Here are the values from the color codes:
#define GL_COLOR_INDEX 0x1900
#define GL_STENCIL_INDEX 0x1901
#define GL_DEPTH_COMPONENT 0x1902
#define GL_RED 0x1903
#define GL_GREEN 0x1904
#define GL_BLUE 0x1905
#define GL_ALPHA 0x1906
#define GL_RGB 0x1907
#define GL_RGBA 0x1908
#define GL_LUMINANCE 0x1909
#define GL_LUMINANCE_ALPHA 0x190A
I believe that is hexa-decimal coding? Perhaps somebody has a convertor up their sleave somewhere?
Thanks!
EDIT: Stuck some more tempChecks in the Texture() function, and I still get 99. It's reading it as a valid texture...
akb825
2006.07.29, 03:12 PM
If you're calling the function the same way, then I see the problem. The problem is, you aren't calling the function: you're simply accessing the address of the function. You need to put () after myJoe.joe. (so it reads myJoe.joe()) I believe you are thinking about the default constructor, which doesn't need parenthesis. I admit, that's rather weird of them to do, but functions still need parenthesis regardless of whether or not you need to pass in parameters.
Jones
2006.07.29, 05:03 PM
If you're calling the function the same way, then I see the problem. The problem is, you aren't calling the function: you're simply accessing the address of the function. You need to put () after myJoe.joe. (so it reads myJoe.joe()) I believe you are thinking about the default constructor, which doesn't need parenthesis. I admit, that's rather weird of them to do, but functions still need parenthesis regardless of whether or not you need to pass in parameters.
Nothing is done in the constructor, except for setting some stuff to true/false, etc. (IE: no functions are called) Do I still need the ()'s?
akb825
2006.07.29, 08:51 PM
If the constructor doesn't take any parameters, you don't need parenthesis. Functions, however, always need parenthesis.
class joe {
joe();
};
joe::joe() {
cout << "Hello, World!" << endl;
int main() {
joe myJoe;
myJoe.joe;
}
}
...is it just me, or is your main nested inside your constructor? I'm hoping that's just an example of what you mean, because that shouldn't even compile.
You shouldn't have to call the constructor manually. And that sample has the constructor as private. Again, shouldn't even compile.
This version should actually work:
#include <iostream>
using namespace std;
class joe
{
public:
joe();
};
joe::joe()
{
cout << "Hello, World!" << endl;
}
int main()
{
joe myJoe;
}
Jones
2006.07.29, 10:44 PM
Woops, yeah that was just a typing error, in my real code the class is in a seperate file from the main stuff.
Good for you, pointing that out, though. :)
Do PNG's encode as BGRA, or RGBA? (Do then even have a standard set display mode?)
I'm guessing no, (to the set display mode), that would be too easy to be true.
OneSadCookie
2006.07.29, 11:52 PM
PNGs can be 8-bit (paletted), 8-bit (grayscale), 16-bit (paletted), 16-bit (grayscale), 24-bit (true color / 8 bits per channel), 32-bit (true color / 8 bits per channel / alpha), 48-bit (true color / 16 bits per channel) and 64-bit (true color / 16 bits per channel / alpha), IIRC. It also supports amusing features like compression, interlacing, and gamma correction.
If you're reading PNGs, you should be using libPNG (or another library which uses it indirectly). There is absolutely no reason to make your life a living hell by trying to write the code yourself.
Jones
2006.07.30, 12:13 AM
PNGs can be 8-bit (paletted), 8-bit (grayscale), 16-bit (paletted), 16-bit (grayscale), 24-bit (true color / 8 bits per channel), 32-bit (true color / 8 bits per channel / alpha), 48-bit (true color / 16 bits per channel) and 64-bit (true color / 16 bits per channel / alpha), IIRC. It also supports amusing features like compression, interlacing, and gamma correction.
If you're reading PNGs, you should be using libPNG (or another library which uses it indirectly). There is absolutely no reason to make your life a living hell by trying to write the code yourself.
Well, it's not working, so I went back to Devil to see what I'd done to get TIFF's to work (partially). It tints my green helicopter pink if I force GL_RGBA or ask devil to tell GL what to use. If I force GL_BGRA it tints it blue. Hmm, I'm gonna blame this on photoshop and pixen. That will postpone the pain of realizing I'll have to get the libpng to work.
I'll go find some sample tiffs on the net to try out...
EDIT:
<laughs at something not even remotely funny>
HAHA!
</laughs at something not even remotely funny>
<exaggerates to vent rage>
It was Pixen all along! That lousy peice-o-smurf gong-show, bargain-mart trash software...
</exaggerates to vent rage>
Well, not quite. But that's the second format it encodes badly. Which is funny because every other app I try the image with it displays fine, I think it's the bit depth checking or something in DevIL. It expects me to specify the strange number of colors or something I'd guess, but I couldn't do that, because I had no idea that's how pixen saved it. That's my guess. Oh well, things are gonna start to work now, (finally) I hope.
OneSadCookie
2006.07.30, 01:06 AM
You might find that FreeImage (http://freeimage.sourceforge.net/) works better than DevIL. Certainly I've used it without issue on Windows, Linux/x86, Mac OS X/ppc without issue, and the (very minor) bug that prevented it working on Mac OS X/x86 appears to be fixed.
Jones
2006.07.30, 03:05 PM
You might find that FreeImage (http://freeimage.sourceforge.net/) works better than DevIL. Certainly I've used it without issue on Windows, Linux/x86, Mac OS X/ppc without issue, and the (very minor) bug that prevented it working on Mac OS X/x86 appears to be fixed.
Ooh... alternatives. :blink: :shock:
Thanks, I'll try this out...
Jones
2006.07.30, 05:18 PM
Sorry to bug all of you again.:blush:
I used the makefile the build FreeImage. It completed the .a, but couldn't make the dylib. They're the same (but different) so no worries there. I know I just chuck the library into my xCode project, but I don't know what to include. The source didn't seem to come with any "include" directory, which might indicate the headers.
There are some FreeImage.h headers in the "source" folder, could those be them, or are they part of FreeImages actual source?
I'm pretty sure that's it. Bit strange that they chucked their def headers in with the actual source. I'll try sorting them out.
OneSadCookie
2006.07.30, 06:27 PM
IIRC, you just need the one "FreeImage.h" header.
It not building a dylib is probably a good thing ;)
akb825
2006.07.30, 07:11 PM
If it's GPL, then making it a dynamic library (or framework) is necessary if you want to use it in a non-open source project.
OneSadCookie
2006.07.30, 07:17 PM
If it's GPL, building a dynamic library won't help :p
If it's LGPL, then yes, you'd need a dynamic library.
However, whilst it is available under the GPL, it is also available under its own very peculiar license which is much less restrictive.
Jones
2006.07.31, 03:49 PM
Oh great, now I have to worry about licensing issues. :p
That's one of the reasons I like to use my own Code, it's mine. I couldn't tell you anything about GPL, other than the fact that it means Free Stuff. As far as I know, I'm allowed to for example, sell a game I made with a lib/framework as long as the creators say so, regardless of whatever GPL says on the subject, if anything.
Link to a copy of the original GPL?
And what's the difference between static and dynamic libraries? Static gets built into my program when I compile, and dylib is called up by the program from another location when it runs, correct?
Jones
2006.07.31, 03:57 PM
Nevermind, I got off my lazy arse and found one. :D
Now I'm gonna have to track down software specific licenses for API's I use...
EDIT: *Freedom* eh? Riigghhhttt... :rolleyes:
akb825
2006.07.31, 09:12 PM
If it's GPL, building a dynamic library won't help :p
If it's LGPL, then yes, you'd need a dynamic library.
However, whilst it is available under the GPL, it is also available under its own very peculiar license which is much less restrictive.
Thanks for the clarification. After seeing this, I checked all the libraries that I was planning on using for my stuff, and I'm happy to say that the most restrictive was under the LGPL. :)
Jones
2006.08.01, 02:27 AM
I've never been very good with legal junk, perhaps one could explain a few aspects of the GPL to me?
I can redistribute for example, I can modify <example GPL thing> (for example, stick it in a framework with some other stuff I wrote) and redistribute (for free) as long as I include the source to it, along with a list of the modifications (if any) I made to the <example GPL thing>?
What if I used <example GPL thing> to make a shareware appliction/game (something I wanted to sell) I could not, except charge for the fee of transffering it, or for a warranty.
What licenses are OpenGL and GLUT under? :???:
Aye... I have a feeling this is gonna get very complicated, very quickly.
But under GPL, I could modify/rebuild source for any <example GPL thing> and redistribute as it my "right"? Regardless of the what the orginal author says/wants?
Thanks!
OneSadCookie
2006.08.01, 03:49 AM
OpenGL and GLUT are APIs, and therefore not under any license.
Apple's implementation of OpenGL and GLUT are under a license that allows you to use them for free without paying or acknowledging that you are using them in any way.. but you can't redistribute them, obviously.
The GPL means that you must always make the source freely available. It doesn't say anything about whether or not you can charge for pre-compiled versions of the software, or anything like that.
Your assets (textures, models, etc) will still be under your copyright.
Jones
2006.08.01, 11:56 AM
OpenGL and GLUT are APIs, and therefore not under any license.
Apple's implementation of OpenGL and GLUT are under a license that allows you to use them for free without paying or acknowledging that you are using them in any way.. but you can't redistribute them, obviously.
The GPL means that you must always make the source freely available. It doesn't say anything about whether or not you can charge for pre-compiled versions of the software, or anything like that.
Your assets (textures, models, etc) will still be under your copyright.
Ahh, thanks! That's what I figured, but it says somewhere in there about all related assets of the program...
You'd just have to break the code enough to make it impossible for them to decode your license system. :lol:
Jones
2006.08.01, 12:19 PM
Ahh, thanks! That's what I figured, but it says somewhere in there about all related assets of the program...
You'd just have to break the code enough to make it impossible for them to decode your license system. :lol:
On a less related note,
Does the GDB debugger *always* give the correct value for variables it lists? Because it's listing "1229213746" as a value for one of my values, and if it really was, my program would have stopped long before the the crash.
OneSadCookie
2006.08.01, 05:39 PM
Ahh, thanks! That's what I figured, but it says somewhere in there about all related assets of the program...
It does? I don't see anything in a quick skim...
OneSadCookie
2006.08.01, 05:44 PM
Does the GDB debugger *always* give the correct value for variables it lists? Because it's listing "1229213746" as a value for one of my values, and if it really was, my program would have stopped long before the the crash.
If you've built your program with -O0 ("no optimization") and -g ("debugging information") then it *probably* won't lie. If you've used a higher level of optimization, it almost certainly will.
Check this by looking in the detailed build logs -- Xcode's build configuration system is too complicated to be absolutely certain that you've got the right settings just by looking there ;)
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.