View Full Version : Easy Pixel Format Question
09-23-2004, 02:05 PM
I am a long time programmer who is finally taking the plunge ito open GL.. I can't get this simple program to behave the way I would expect it to. I'm simply trying to draw a 100x100 square full of randomly colored pixels. Instead, I get a square with randomly colored pixels, and a severe vertical striping type effect. I have tried everything I could think of with glPixelStorei, but It doesn't change...
//Graphical "Hello World" routine : random square
glDrawPixels(100, 100, GL_RGB, GL_UNSIGNED_BYTE,Square);
THANKS FOR YOUR HELP GUYS!
09-23-2004, 11:01 PM
GLubyte *Square[100*100*3]; How about using:
GLubyte Square[100*100*3]; Instead ?
Your code allocates 30000 byte pointers, the second allocates 30000 bytes.
This means that each random value you put in there will use up 4 bytes NOT one as I assume you want.
The result would be 1 random colord pixel and 3 black pixels and then same thing over and over again, is this the problem you have ?
Sounds like disabled v-sync. Set V-Sync to be enabled on default under windows. (Desktop->Right Click -> Properties -> Display Settings -> Advanced Settings).
09-24-2004, 09:46 AM
I knew it was something stupid like that!
09-24-2004, 10:08 AM
I am learning Cocoa and oGL at the same time after many many years of C++ and Intel 13h graphics expereince. I know algoritms and theory but I'm a newbie once again in the actual implimentation and syntax. I'm trying to figure out the best way to hold large arrays for graphics. (Which can then be manipulated with my algorithms)
So in that note, what's wrong with:
The same program from above, when enlarged to 720x486 instead of 100x100 crashes.
thanks for your help guys
MAybe its not the best idea to allocate huge arrays on stack. :D
09-24-2004, 10:24 AM
(Psst I'm a mathematician not a programmer.. some crossover, but not with stuff like dealing with the memory.. still learning)
09-24-2004, 10:47 AM
I have noticed in my educational life in general, that people are often severely lacking in fundamentals. Instructors so often glaze over the very basic "moves" in math and related subjects. The instructors categorize them as "automatic", in their own minds, and then the importance is lost on the students.
This is why I will ask questions, even stupid ones, because I am trying to build up the fundamentals of programming.
So thanks <me>.. now I know that not only is it "bad" to declare large array variables inside "the stack" but it actually crashes the program. Thats good, (now obvious) important information for a beginner that none of the literature I read mentioned.
And this is after I have already written things like realtime fourier transformers and other "advanced" programs.
Teaching yourself something is really hard because these fundamentals are rarely adressed directly. So the web boards like this become EXTREMELY valuable!
09-24-2004, 10:52 PM
GLUbyte* vector = (GLUbyte*) malloc( 100*100*3);
... do something with it...
Or you can of course use new/delete instead in C++.
The space available on the stack is usually not that big by default even though many times you can set it with an argument to the linker.
So use malloc/free or new/delete for larger objects.
Originally posted by typewriter:
I have noticed in my educational life in general, that people are often severely lacking in fundamentals. Instructors so often glaze over the very basic "moves" in math and related subjects. The instructors categorize them as "automatic", in their own minds, and then the importance is lost on the students.I already noticed that myself, thats why I answered you. Still I couldnt resist placing the smilie. ;)
Maybe you saw a new thread with another basic question opened be me ( I should have used a more unique name not already registered by someone :rolleyes: ).
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.