Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  new to OpenGL, could use some help  (Read 1088 times)
0 Members and 1 Guest are viewing this topic.
Offline Wildern

Junior Member





« Posted 2010-06-02 19:03:39 »

Basically, I am being forced to use OpenGL to do my drawing (by a 3rd party application that I cannot avoid).
I need to be able to draw in image from a png file.  I need to be able to rotate that image.  Both of these, I have working.  What I need help with it figuring out how to clip the image.  Basically, the image is large and I want to have a small viewport with the image moving/rotating inside it.  The viewport would stay fixed (a small square) and the image I am drawing would pan/rotate behind the viewport square and be clipped to fit within the viewport square (I hope that made sense)

I am currently loading the file and drawing the image as a texture as follows:
(I modified example code to get to here, so please let me know if I am doing this  part incorrectly as well)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
m_imageList = gl.glGenLists(1);
gl.glNewList(m_imageList, gl.GL_COMPILE);
gl.glPushMatrix();
gl.glTranslatef(-0.5, -0.5, 0.0);
gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE);
gl.glEnable(gl.GL_TEXTURE_2D);
gl.glBindTexture(gl.GL_TEXTURE_2D, textureID);
gl.glBegin(gl.GL_QUADS);
gl.glTexCoord2f(0.0, 0.0);
gl.glVertex2f(0.0, 0.0);
gl.glTexCoord2f(1.0, 0.0);
gl.glVertex2f(1.0, 0.0);
gl.glTexCoord2f(1.0, 1.0);
gl.glVertex2f(1.0, 1.0);
gl.glTexCoord2f(0.0, 1.0);
gl.glVertex2f(0.0, 1.0);
gl.glEnd();
gl.glPopMatrix();
gl.glEndList();

//later, the drawing....

gl.glPushMatrix();
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glTranslate(x, y, 0.0);
gl.glScalef(256.0, 32.0, 0.0); //actual image size
gl.glColor4f(1.0, 1.0, 1.0, 0.5); //50% transparent
gl.glCallList(m_imageList);
gl.glPopMatrix();
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #1 - Posted 2010-06-02 19:06:49 »

use glScissor if you don't want to use glViewport

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline Wildern

Junior Member





« Reply #2 - Posted 2010-06-02 19:25:06 »

I appreciate the response, but I have attempted to use both of those (I *really* have no clue what I am doing here)

My attempt to use glViewPort resulted in all my images being scaled down to the size of the viewport instead of being clipped, and glScissor doesn't appear to do anything.

I am working within another application's OpenGL context and when it is done drawing, I get a callback letting me know it is safe for me to draw.
Games published by our own members! Check 'em out!
Try the Free Demo of Revenge of the Titans
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #3 - Posted 2010-06-02 19:27:31 »

glEnable(GL_SCISSOR_TEST);   

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline Wildern

Junior Member





« Reply #4 - Posted 2010-06-02 19:31:49 »

Any idea what the value for that constant should be as all of the Enable constants are commented out of the api wrapper I have to use?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #5 - Posted 2010-06-02 19:34:01 »

According to:
http://www.blackberry.com/developers/docs/5.0.0api/constant-values.html

public static final int   GL_SCISSOR_TEST   3089

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline Wildern

Junior Member





« Reply #6 - Posted 2010-06-02 19:39:26 »

I managed to get glScissor working.
Thank you Riven!!!!!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (88 views)
2013-05-17 21:29:12

alaslipknot (96 views)
2013-05-16 21:24:48

gouessej (128 views)
2013-05-16 00:53:38

gouessej (123 views)
2013-05-16 00:17:58

theagentd (131 views)
2013-05-15 15:01:13

theagentd (119 views)
2013-05-15 15:00:54

StreetDoggy (161 views)
2013-05-14 15:56:26

kutucuk (184 views)
2013-05-12 17:10:36

kutucuk (185 views)
2013-05-12 15:36:09

UnluckyDevil (191 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.13 seconds with 21 queries.