Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  2 questions  (Read 2371 times)
0 Members and 1 Guest are viewing this topic.
Offline g666

Junior Member





« Posted 2005-11-10 13:05:39 »

question1:
how to get it so the viewwindow is bound to the 3d coords? eg so that the view window is coupled onto the end of a cuboid in 3d space?

quesion2:
what is a file format that can have different colors for each vertex. You cant do this with obj which i made a loader for.

desperately seeking sanity
Offline Mr EEK

Senior Newbie





« Reply #1 - Posted 2005-11-10 13:22:28 »

1.  You can move your view around by multiplying your projection matrix by other transformation matrices (i.e. translate, rotate etc.) so you can move it about as if it were attached to a moving "cube" in space.

2.  OBJ format supports materials (which look a lot like OpenGL materials), although not all descriptions of OBJ mention this.  Take a look at:

http://www.csit.fsu.edu/~burkardt/data/obj/obj_format.txt
Offline g666

Junior Member





« Reply #2 - Posted 2005-11-12 22:51:45 »

I have updated my obj loader so it supports mtls, textures and normals, however now i realise that many of the supplied texuteres do not have dimensions that are a power of 2. To remedy this i find the next biggest power of 2 and stretch the texture using j2d, but i realy would like to be able to do it some other way without using awt/imagio, how can i do this.

Also im not to sure how to implement transparency, in the mtl files, transparency is specified as a value between 0 and 1, how can i draw the surface with this transparency, which blennd function do i need to use.

Also: Im not usre what is the most expensive operations in opengl, but i hear that changing materials and binding textures is quite expensive. shoudl i build some sort of tree so i can draw the plygons changing these as few times as possible?

desperately seeking sanity
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mr EEK

Senior Newbie





« Reply #3 - Posted 2005-11-15 13:14:08 »

Hi g666,

I don't know for sure, but I think the devIL library that comes with LWJGL can do the texture resizing for you so that you can avoid AWT.
Offline kevglass

JGO Kernel


Medals: 122
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #4 - Posted 2005-11-15 13:54:31 »

Quote
I have updated my obj loader so it supports mtls, textures and normals, however now i realise that many of the supplied texuteres do not have dimensions that are a power of 2. To remedy this i find the next biggest power of 2 and stretch the texture using j2d, but i realy would like to be able to do it some other way without using awt/imagio, how can i do this.

You might find adjusting your texture coordinates rather than stretching the original image is easier.

Kev

Offline g666

Junior Member





« Reply #5 - Posted 2005-11-15 21:58:54 »

but ogl wont let me have me have non power of 2 textures, unless there is some feature that id ont know about Huh (uite likely Tongue)

desperately seeking sanity
Offline kevglass

JGO Kernel


Medals: 122
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #6 - Posted 2005-11-15 22:21:42 »

Na, you still have non-power of two textures, you just leave the image the same size, only fill the bit of the texture you have then adjust the texture coordinates to match the size of the image..

so, if you image was 24x24, the texture ends up being 32x32... and you texture coordinates end up being 0,0 to (24f/32f,24f/32f)

Kev

Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #7 - Posted 2005-11-15 22:25:47 »

And you don't obviously know about.... the ARB_texture_non_power_of_two and ARB_texture_rectangle extensions! Cool

Cas Smiley

Offline g666

Junior Member





« Reply #8 - Posted 2005-12-02 10:36:32 »

Why didnt you tell me about the gluScaleImage method?
now why wont this work?(it fails with an index out of bounds exception in that method)

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  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
package com.ts.terestria.client.lwjglrenderer;

import org.lwjgl.*;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.glu.*;
import org.lwjgl.devil.*;

import java.nio.*;
import java.util.HashMap;

public class TextureCache{
   
   /*
    *cannot be instanstiated
   */

   private TextureCache(){}
   static{
      init();
   }
   
   //Strings as keys for Texture Objects
  private static HashMap textures = new HashMap();
     
   public static void init(){
      try{
         IL.create();
      }catch(LWJGLException e){}
   }
   
   
   /**
    *returns a Texture, loading it if neccasary and adding it to the cache
    */

   public static Texture getTexture(String path){
      //need to load it?
     if(!textures.containsKey(path))
         textures.put(path, loadTexture(path));
      return (Texture) textures.get(path);
   }
   
   
   /*
    *returns a texture object loaded from the specified path
   */

    public static Texture loadTexture(String path){

        ByteBuffer scratch = getImageData(path);
       
        int width = IL.ilGetInteger(IL.IL_IMAGE_WIDTH);
        int height = IL.ilGetInteger(IL.IL_IMAGE_HEIGHT);
       
       int newWidth=width, newHeight=height;

        //scale image?
       if(!isPOT(width) || !isPOT(height)){
           
           int newWidth = getNextPOT(width);
           int newHeight = getNextPOT(height);
           ByteBuffer scaled = ByteBuffer.allocateDirect(newWidth*newHeight*4);
                     
           //returns 0 on success, else a GLU error code
          int retVal = GLU.gluScaleImage(
                          GL11.GL_RGBA,
                                width,
                                height,
                                GL11.GL_UNSIGNED_BYTE,
                                scratch,
                                newWidth,
                                newHeight,
                                GL11.GL_UNSIGNED_BYTE,
                                scaled);

                scratch = scaled;

           if(retVal != 0){
              System.out.println("something went wrong scaling texture");
              System.exit(1);
           }
        }
       
        // Create A IntBuffer For Image Address In Memory
       IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
        GL11.glGenTextures(buf); // Create Texture In OpenGL

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
        // Typical Texture Generation Using Data From The Image

        // Linear Filtering
       GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        // Linear Filtering
       GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        // Generate The Texture
       GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, newWidth, newHeight,
           0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, scratch);
               
       // buf.get(0) == Image Address In Memory
       return new Texture(buf.get(0), width, height);
   }
   
   
   /**
    *returns a byte buffer of image data loaded from the specifed path
    */

   public static ByteBuffer getImageData(String path){
      IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
        IL.ilGenImages(image);
        IL.ilBindImage(image.get(0));
        IL.ilLoadImage(path);
        IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);
        ByteBuffer scratch = ByteBuffer.allocateDirect(IL.ilGetInteger(IL.IL_IMAGE_WIDTH) * IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 3);
        IL.ilCopyPixels(0, 0, 0, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 1, IL.IL_RGB, IL.IL_BYTE, scratch);
        return scratch;
   }
   
   
   /**
    *returns the next POT, if n is POT then it returns n
    */

   public static int getNextPOT(int n){
      int i = 1;
      while(i < n){
         i *= 2;      
      }
      return i;
   }
   
   
   /**
    *returns if n is POT
    */

   public static boolean isPOT(int n){
      return getNextPOT(n) == n;
   }
}

desperately seeking sanity
Offline g666

Junior Member





« Reply #9 - Posted 2005-12-05 14:46:08 »

Hello? Anybody out there? Undecided

desperately seeking sanity
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (24 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
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!