Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / OpenGL Development / rendering arc on: 2012-03-04 15:04:51
hello guys, i need your help with this.. i've been trying to render an arc in OpenGL but all i'm getting at always is an oval..

here is the code

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  
   private void renderArc(float x, float y, float width, float height,
         float start, float end, int cap)
   {
      float theta;
      float angle_increment;
      float x1;
      float y1;

      angle_increment = (float) (2 * MathHelper.pi()) / 90;
     
      GL11.glPushMatrix();

      GL11.glTranslatef(x + (width / 2), y + (height / 2), 0);

      this.setProperties();

      GL11.glBegin(cap);
      for (theta = start; theta < end + angle_increment; theta += angle_increment)
      {
         x1 = (float) ((width / 2) * Math.cos(theta));
         y1 = (float) ((height / 2) * Math.sin(theta));

         GL11.glVertex2f(x1, y1);
      }
      GL11.glEnd();

      GL11.glPopMatrix();

      GL11.glColor3f(1.0f, 1.0f, 1.0f);
   }
2  Java Game APIs & Engines / OpenGL Development / Re: Draw Oval in OpenGL on: 2011-12-19 23:06:41
yeah.. i am quite an idiot for not noticing that..  Grin thanks anyway..  Grin
3  Java Game APIs & Engines / OpenGL Development / Re: Draw Oval in OpenGL on: 2011-12-19 23:05:39
ok i found out what's wrong.. i should have used 2*Math.PI instead of just one since the circle has a range of 2*PI radians..  Grin
4  Java Game APIs & Engines / OpenGL Development / [SOLVED] Draw Oval in OpenGL on: 2011-12-19 22:59:34
hi.. can you guys help me with this..

i want to implement a draw oval function for opengl.. i am using lwjgl btw.. here is my code so far..

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  
   public void drawOval(int x, int y, int width, int height) {
      float theta;
      float angle_increment;
      float x1;
      float y1;
     
      angle_increment = (float) Math.PI / 500;
      GL11.glPushMatrix();
     
      GL11.glTranslatef(x+(width/2), y+(height/2), 0);

      GL11.glColor4f(
            this.color.getRedComponent()/255,
            this.color.getGreenComponent()/255,
            this.color.getBlueComponent()/255,
            this.color.getAlpha()/255
            );
         
      GL11.glBegin(GL11.GL_LINE_LOOP);
      for(theta = 0.0f; theta < Math.PI; theta += angle_increment) {
         x1 = (float) (width/2 * Math.cos(theta));
         y1 = (float) (height/2 * Math.sin(theta));

         GL11.glVertex2f(x1, y1);
      }
      GL11.glEnd();
     
      GL11.glPopMatrix();
   }


this function draws only the lower half of the circle.. idk how to fix it, any help is appreciated.. thanks in advance Smiley
5  Game Development / Newbie & Debugging Questions / Drawing Polygons and Ellipses using LWJGL on: 2011-12-08 06:59:22
hi can anyone help me with this.. i am new to OpenGL.. i'm currently using LWJGL.. actually i am modifying
GTGE interface for LWJGL.. when examining the code, i found that there is no implementation for drawing arcs, circles, etc.

I am confused with how OpenGL works so I find it hard to solve this by myself.. any help is appreciated.. thanks in advance Smiley
6  Java Game APIs & Engines / J2ME / Active Rendering in J2ME on: 2011-12-07 16:49:10
hi guys.. my problem is that idk how to implement an active rendering in J2ME..

i've tried to do so, however the application is not working.. nothing happens after I run the program..

here is my source code..

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public StandardMobileMode(boolean suppressKeyEvents, javax.microedition.lcdui.Display display) {
      super(suppressKeyEvents);
      this.display = display;
      this.currentGraphics = new MIDletGraphics();
   }

   public Graphics getBackBuffer() {
      currentGraphics.setGraphics(this.getGraphics());
      return currentGraphics;
   }

   public boolean flip() {
      this.flushGraphics();
      return true;
   }


btw this is based from GTGE engine.. the getBackBuffer() function returns graphics object from the canvas.. the StandardMobileMode is a subclass of GameCanvas..

this is how i initialized the game canvas.. the class containing this function is a subclass of MIDlet..

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public void setup(Game game) {
      try {
         engine.mountGame(game);
         /* Initialize File IO */
         engine.fileIO = new MobileIO();
         /* Initialize Display */
         javax.microedition.lcdui.Display display = javax.microedition.lcdui.Display.getDisplay(this);
         engine.display = new StandardMobileMode(false, display);
         /* Initialize System Time */
         engine.timer = new StandardTimer();
      } catch(Exception e) {
         System.exit(-1);
      }
   }
   


and this is how my gameloop works...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
      while(isRunning) {
         if(!isPaused) {
            this.game.update(elapsedTime);
         }
         
         do {
            if(!isRunning) {
               break;
            }
            Graphics g = display.getBackBuffer();
            this.game.render(g);
         } while(!this.display.flip());
         
         elapsedTime = this.timer.sleep();
         if(elapsedTime > 100) {
            elapsedTime = 100;
         }
      }


i can't seem to make this run.. all i get is a blank screen.. can somebody help me? thanks in advance..Smiley
7  Java Game APIs & Engines / OpenGL Development / Re: Problem with OpenGL via LWJGL on: 2011-12-06 19:48:12
it's just as you said, i was thinking of the same about the color but idk what to do, i thought i need GL.glFlush(), silly me  Roll Eyes .. but anyway, it works now  Grin thanks alot  Smiley
8  Java Game APIs & Engines / OpenGL Development / [SOLVED] Problem with OpenGL via LWJGL on: 2011-12-06 19:34:19
hi guys.. first and foremost.. this is my first post, idk if this is the right section.. but here it goes..

i'm working on a project.. it's a game programming library, focusing on portability in the java environment.. i am currently working on the display function.. as a system dependency, J2SE can use OpenGL for its graphics functionalities such as display or for rendering, etc..

i'm not doing things from scratch, my adviser (now on temporary leave) told me to look for some open source libraries in the Internet to lighten my load.. I found LWJGL which provides classes and interface for OpenGL.. so i use it for the J2SE OpenGL module of my library..

the program i've written so far works perfectly for basic polygon rendering in both OpenGL and native hardware accelerated graphics.. however, when I proceed to image rendering there seems to be some problem..



the image above shows the output after i run the OpenGL rendering program..

here is the code for initializing LWJGL

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  
31  
32  
33  
34  
35  
36  
37  
38  
39  
private void initGL() {
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glDisable(GL11.GL_DEPTH_TEST);
 
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
 
      GL11.glOrtho(0, this.size.width, this.size.height, 0, -1, 1);
 
      GL11.glEnable(GL11.GL_BLEND);
      GL11.glClearColor(0, 0, 0, 0);
 
      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
   }
 
   private void initGraphics() {
      try {
         DisplayMode best = (this.isFullscreen) ?
               this.getBestDisplayMode(size) : new DisplayMode(
                     this.size.width, this.size.height);
 
         if(best == null) {
            throw new Exception();
         }
 
         org.lwjgl.opengl.Display.setDisplayMode(best);
      } catch(Exception e) {
 
      }
 
      try {
         org.lwjgl.opengl.Display.setTitle(this.title);
         org.lwjgl.opengl.Display.setFullscreen(this.isFullscreen);
         org.lwjgl.opengl.Display.setVSyncEnabled(this.usingVsync);
         org.lwjgl.opengl.Display.create();
      } catch(Exception e) {
 
      }
   }


and here is the code for rendering the image:

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  
31  
32  
33  
34  
public boolean drawImage(Image img,
                      int x, int y, int width, int height,
                      ImageObserver observer) {
      startPainting();
 
 
      GL11.glPushMatrix();
 
       Texture texture = textureLoader.getTexture((BufferedImage) img);
      texture.bind();
 
      GL11.glTranslatef(x, y, 0);
 
      GL11.glBegin(GL11.GL_QUADS);
         GL11.glTexCoord2f(0, 0);
         GL11.glVertex2f(0, 0);
 
         GL11.glTexCoord2f(0, texture.getHeight());
         GL11.glVertex2f(0, height);
 
         GL11.glTexCoord2f(texture.getWidth(), texture.getHeight());
         GL11.glVertex2f(width, height);
 
         GL11.glTexCoord2f(texture.getWidth(), 0);
         GL11.glVertex2f(width, 0);
      GL11.glEnd();
 
      GL11.glPopMatrix();
 
 
      endPainting();
 
       return true;
    }


oh btw here is how i called the rendering routine:

1  
2  
3  
4  
5  
public void render(Graphics g) {
      g.setColor(Color.RED);
      g.fillRect(0, 0, 640, 480);
      image.render(g, 0, 0);
   }


any help to make the OpenGL rendered image look exactly like the image below? thanks in advance Smiley

Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (44 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (38 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (87 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!