Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Simple Questions

Simple Questions
Thread Tools
Fresh-Faced Recruit
Join Date: Sep 2000
Status: Offline
Reply With Quote
Jul 5, 2001, 08:07 AM
 
Alright, I'm trying to get an NSOpenGLView working, and so far, have had mixed success. I've been able to get the rendering working, no problem. I did this by subclassing NSOpenGLView, and overriding the drawRect function. Great.

Now, when the view gets resized, I want to adjust the perspective using gluPerspective. gluPerspective takes a GLfloat which I want to be the ratior of width to height. I cannot get this working. This is mostly a cocoa problem, not an opengl one. When the view is resized, I override the resize function, and was trying to get the appropriate values as follows:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
NSRect* myRect = [<font color = purple>self</font> frame];
GLfloat myWidth = [myRect width]; <font color = brown>// These calls dont work</font>
GLfloat myHeight = [myRect height];

GLfloat myWidth2 = [ [myRect size] width ]; <font color = brown>// These dont either</font>
GLfloat myWidth2 = [ [myRect size] height ];
</font>[/code]

I also tried various casts, and such. The Cocoa (java) api docs implement the functions exactly as I need them, but are in java, whereas I need c. This has to be pretty simple, so why am I having such a hard time? Anyone want to help me out here...

Also, why is it so hard to find the objC documentation as opposed to the Java docs? And does anyone have further examples of calling OpenGL with Cocoa, both in a view similar to what I mention above, and in full screen mode?

Thanks.

Spencer
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Jul 5, 2001, 09:34 AM
 
In ObjC, NSRect is a C structure, not an object. Java doesn't have structures so it's an object there. The same goes for NSSize, NSPoint, and NSRange. The ObjC documentation is therefore not under the Classes directory, but rather the TypesAndConstants and Functions directories.

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
<font color = brown>// NSRect, not NSRect * -- the structure is returned by value</font>
NSRect myRect = [<font color = purple>self</font> frame];
GLfloat myWidth = myRect.size.width;
GLfloat myHeight = myRect.size.height;
GLfloat myWidth2 = NSWidth(myRect); <font color = brown>// <font color = green>this</font> will work too</font>
GLfloat myHeight2 = NSHeight(myRect);
</font>[/code]
     
Fresh-Faced Recruit
Join Date: Sep 2000
Status: Offline
Reply With Quote
Jul 5, 2001, 11:06 AM
 
Thanks lindberg. I thought I was losing my mind, there, for a while! Very helpful.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:44 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2