Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Is it possible to load a texture using the NDK, but pass the result back to use in java.

I have used the code in the link above and it appears to load the png correctly and generates a texture ID without an error (the id is 0 before the loading function is called and non-zero afterwards).

Is it not allowed to mix opengl operations between C++ and java?

Thanks for your help All the best, Ash

share|improve this question
    
The question is not clear. Yes, it is allowed to mix OpenGL operations between C++ and Java. But I don’t think this is really what you are asking. Are you having a problem doing so? If so, please explain what you are doing and what happens. –  Sam Hocevar Apr 10 '11 at 18:55
add comment

1 Answer

up vote 1 down vote accepted

I do quite a bit of the opposite -- I leverage the Android facilities for loading images from disk and into OpenGL, and then return the texture ID back over JNI.

So basically, I have native code, a JNI bridge, and then a series of utility functions in Java that do the actual work, and my call sequence looks something like:

[native code] -> [JNI code] -> [Java Code]

and of course the texture ID is passed back to native code. There's no reason this can't work the other way around, though I have to wonder what compels you to do so, since it's so easy to do in Java/Android as it is. What is the problem you're encountering?

Make sure you aren't attempting to make OpenGL calls simultaneously from multiple threads, and check to see if the OpenGL error flag is being set anywhere.

share|improve this answer
    
A reason for doing so would be if the image format could not be read from Java, or if the texture required important CPU resources (procedural textures, or various effects). I do the exact opposite, too, but I don’t see either why the texture ID couldn’t be passed back to Java. –  Sam Hocevar Apr 10 '11 at 18:53
    
Hi @stephelton, thanks for your reply. I have some C++ code from a iPhone project i'd like to use (for loading a font texture and texture co-ords), but I'd like to do the majority of the opengl stuff in java (as it's easier to access resources and assets). I'm not doing any threading stuff yet, unless it's done automatically? Thanks! Ash –  Ash McConnell Apr 10 '11 at 18:59
1  
GLSurfaceView will run your renderer in its own thread. So if you're using this class, you should not do any OpenGL work anywhere else (generally only in its onDrawFrame(), onSurfaceCreated(), and onSurfaceChanged() methods) –  stephelton Apr 11 '11 at 14:56
    
/ Sam. Sorry for not getting back earlier, my son is in hospital and my laptop is in here to stop my wife going crazy. Aha, I use GLSurfaceView. Is there another way of using openGL? A normal game loop perhaps? I'll do some googling on the subject. Thanks for the help! –  Ash McConnell Apr 11 '11 at 21:03
    
Ah, I finally understand what you were saying in the comment above. I moved the call to my native texture loading code to onSurfaceCreated and all works fine now! Thanks for your help! –  Ash McConnell Apr 25 '11 at 13:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.