OpenGL Texture not displaying - my first class.
akb825 Wrote: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.
Well, I stuck this in my init()...
Guess what I get back... 0.
Uh... that's not supposed to happen.
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.
Code:
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.

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) {
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) {
Sir, e^iπ + 1 = 0, hence God exists; reply!
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).
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).
unknown Wrote: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.
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.
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.
akb825 Wrote: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?

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.
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.
akb825 Wrote: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.

Code:
class joe {
joe();
};
joe::joe() {
cout << "Hello, World!" << endl;
int main() {
joe myJoe;
myJoe.joe;
}
}
Would return nothing.

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...
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...
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:
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...
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:
Code:
#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...
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.
akb825 Wrote: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?
If the constructor doesn't take any parameters, you don't need parenthesis. Functions, however, always need parenthesis.
Code:
class joe {
joe();
};
joe::joe() {
cout << "Hello, World!" << endl;
int main() {
joe myJoe;
myJoe.joe;
}
}
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:
Code:
#include <iostream>
using namespace std;
class joe
{
public:
joe();
};
joe::joe()
{
cout << "Hello, World!" << endl;
}
int main()
{
joe myJoe;
}
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
OpenGL ES Texture Masking | airfire | 6 | 22,768 |
Mar 17, 2014 07:07 PM Last Post: baioses |
|
OpenGL ES Texture Compression | ajrs84 | 9 | 11,159 |
May 7, 2013 03:36 PM Last Post: ajrs84 |
|
OpenGL ES Texture Masking | dalasjoe sin | 0 | 5,274 |
Apr 13, 2012 12:17 AM Last Post: dalasjoe sin |
|
Texture in OpenGL ES 2 looks pixelated | vunterslaush | 18 | 38,488 |
Aug 30, 2011 09:44 PM Last Post: Frogblast |
|
Another beginner's question about displaying an animated object | superlemonster | 2 | 6,481 |
Jan 28, 2011 08:03 AM Last Post: OptimisticMonkey |