Showing posts with label mac. Show all posts
Showing posts with label mac. Show all posts

Jul 26, 2009

Anything wrong in glShaderSourceARB ?

It cost me many hours to find what was wrong with glShaderSourceARB. When I wrote this :

char v[128] =
"void main(void)\n"
"{\n"
" gl_Position = ftransform();\n"
"}\n";

glShaderSourceARB(shaderVtx, 1, (const GLcharARB**)&v, 0);

My application always crashed in "strlen". But if I change the code to :

char v[128] =
"void main(void)\n"
"{\n"
" gl_Position = ftransform();\n"
"}\n";

const GLcharARB* ppV[1] = {(GLcharARB*)v};

glShaderSourceARB(shaderVtx, 1, ppV, 0);

Everything is fine. Do I forget how to write C ? (Although I insert them in objective-c.) It looks like due to compiler setting since the first one works in sample of xcode.

20090802
Ok, nothing wrong except my careless style. This is a very basic pointer usage problem. "v" in the code does mean the start address of a string, but not a pointer to a string (althought the type is a pointer). That means "&v" is not in the memory. But why the sample works ? Because the sample pass "v" to another function which would generate a new local pointer to v, so we can find this pointer in memory. Luckily, no one would read this article. XD

Jul 21, 2009

Hello Watermelon !


Hello ! Watermelon ! You are so sweet in this summer. Actually, it`s "Hello world" of OpenGL. It`s my first OpenGL program (except the other one with OpenGL ES which is pretty simple). I wanna make something with OpenGL & GLSL & my Mac, that`s the reason why I start to swallow OpenGL.

Jun 17, 2009

why UnAdvise ?

If you are familier with COM, you would usually work with AdviseFooEventSink / UnAdviseFooEventSink. You have to call UnAdviseFooEventSink explicitly somewhere ...... it`s better not in the scope of this event sink, especially in the destructor of event object. But WHY ?

I try to demo something by directshow recently. When working with filter, I made some mistake in accident today. I did something like UnAdviseFooEventSink in the destrucotr of event object. Let`s check what happen :

  1. when the event sink object is created, the reference count should be 1.
  2. when Foo Advise the sink object, reference count of sink object increase to 2.
  3. when I don`t need the sink object anymore and try to release it, reference count decrease to 1.
  4. Now the owner of the sink object is Foo, and I wish sink object to be UnAdvise when being deleted.
  5. Since Foo is still the owner of sink object, sink object won`t be deleted if Foo doesn`t do extra work.

Thanks for the debugging function of baseclass of dshow, I got some ugly assert and try to fix it.

BTW, the same isuue would happen in cocoa of Mac, too. If 2 objects are the owner of each other (retain each other), they should be disconnected before release the final reference outside of the scope.

May 28, 2009

stupid flying triangle

Finally, I rendered a stupid flying triangle in iPhone simulator. Though I never investigate OpenGL before, but it easier than d3d. So writing code to render simple object is quickly. But I am usually confused with gl functions. Like the "glTranslatef", this C function can`t tell me which matrix I try to translate now, just like many old C functions. It`s fortunate that I still don`t have to take care heavily matrix calculation in current stage.

I guess it`s time to start to make a simple game after learning how to render text, since the basic touch function need only override some method in UIView.



BTW, I tried to programming on symbian (sdk from nokia) long long ago. Maybe I was too weak so I could not make the simulator work correctly. I bough a book for that OS, but I never touch them again after several "days". (OK, that happened in 4th month of my programming life).

May 27, 2009

xcode is still not my friend !

Though I said Hello world 3 times, I am still not familiar with xcode. It took me several minutes to check why the debugger can`t work as visual studio. Then I unchecked the "Load symbols lazily" in accident and debugger can stop at the break point in the beginning. I don`t know if visual studio can do the same thing. But it should be useful in somewhere, maybe the symbols can be loaded when application crashing. That will help when debugging a big app. BTW, I don`t know if there is any default app like mspaint.exe in Mac, so there is no mark to show you the position of the option. It is the first one in the right panel. Wish you don`t have to enjoy it... XD

May 18, 2009

New Toy !

I bought a new Mac Book from Apple store last week. I never played Mac OS before, and this made me suffer recently. But Leopard does have a good looking, so maybe I will enjoy in this OS soon.

There is some problems that make me post this in English. First, I don`t know how to change IME in Mac OS. Second, I only use LIU for Chinese, but I think it`s hard to find a Mac version. The main purpose to play this machine is I wanna practice programming in Mac. I don`t know if I could get any help from this domain, but to learn more is always better.

Here is a screen shot from my first GUI program in Mac. A simple window to translate ASCII code to Morse Code. It cost me about 3 hours to make it work, though I can do the same thing by MFC in 10 minutes. The level of AppKit is higher than MFC, so to create a new window application is easier. But if my experience from windows is still work, it`s better to study window programming in lower level. Just like I started ui programming with win32 (yes, register window class, create windows), and that made me better in gui programming till now.
 

BTW, <Learn Objective-C on the Mac> is really good for an experienced C/C++ programmer. Though there are many different feature, it`s possible to pick it up in 4 days. My own problems is how to become more familiar with those new topic, like category & protocol.