Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (854)
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  
  Texturing the VBO triangles problems  (Read 592 times)
0 Members and 1 Guest are viewing this topic.
Offline PrzemoVi

Junior Newbie





« Posted 2017-10-27 21:41:34 »

Hello everyone! Im newbie in the LWJGL 3d rendering and Im trying to texture some terrain generated using heightmap and VBO. But something is wrong with the rendered textures (look into generated terrain):

generated terrain: https://i.imgur.com/TrszUy1.png
used texture: https://i.imgur.com/0mFmqm3.png
(texture is green quad with black edges)

How can I fix this?

Here is full 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  
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  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
    public class NGINE4 {
       int w = 800;
       int h = 600;
       double map[][];
       int Size = 200;
       Texture floor;
       
       public static void main(String[] args) throws Exception {
          NGINE4 ng = new NGINE4();
          ng.start();
       }
   
       void initContext() throws Exception {
          Camera.create();
   
          Display.setDisplayMode(new DisplayMode(w, h));
          Display.setFullscreen(false);
          Display.create();
          GL11.glViewport(0, 0, w, h);
          Mouse.setGrabbed(true);
   
          floor = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("a.png"));
         
          NoiseHeightMap nsh = new NoiseHeightMap(500, 6548816);
          map = nsh.getHeightmap();
       }
   
       void renderLoop() {
          GL11.glEnable(GL11.GL_TEXTURE_2D);
         
          long time = 0;
          int frames = 0;
   
          int vertex_size = 3; // X, Y, Z,
          int color_size = 3; // R, G, B,
          int texture_size = 3; //X, Y, Z
         
          FloatBuffer vBuffer = BufferUtils.createFloatBuffer(9 * (Size * Size * 2));
          FloatBuffer cBuffer = BufferUtils.createFloatBuffer(9 * (Size * Size * 2));
          FloatBuffer tBuffer = BufferUtils.createFloatBuffer(9 * (Size * Size * 2));
          int heightmapExaggeration = 20;
          Random rand = new Random();
          for (int x = 0; x < Size - 1; x++) {
             for (int y = 0; y < Size - 1; y++) {
               
                cBuffer.put(1).put(1).put(1);
                cBuffer.put(1).put(1).put(1);
                cBuffer.put(1).put(1).put(1);
   
                vBuffer.put(x * 0.25f).put((float) (map[x][y] * heightmapExaggeration)).put(y * 0.25f);
                vBuffer.put((x + 1) * 0.25f).put((float) (map[x + 1][y] * heightmapExaggeration)).put(y * 0.25f);
                vBuffer.put(x * 0.25f).put((float) (map[x][y + 1] * heightmapExaggeration)).put((y + 1) * 0.25f);
               
                tBuffer.put(x * 0.25f).put((float) (map[x][y] * heightmapExaggeration)).put(y * 0.25f);
                tBuffer.put((x + 1) * 0.25f).put((float) (map[x + 1][y] * heightmapExaggeration)).put(y * 0.25f);
                tBuffer.put(x * 0.25f).put((float) (map[x][y + 1] * heightmapExaggeration)).put((y + 1) * 0.25f);
   
                cBuffer.put(1).put(1).put(1);
                cBuffer.put(1).put(1).put(1);
                cBuffer.put(1).put(1).put(1);
   
                vBuffer.put((x + 1) * 0.25f).put((float) (map[x + 1][y + 1] * heightmapExaggeration)).put((y + 1) * 0.25f);
                vBuffer.put((x + 1) * 0.25f).put((float) (map[x + 1][y] * heightmapExaggeration)).put(y * 0.25f);
                vBuffer.put(x * 0.25f).put((float) (map[x][y + 1] * heightmapExaggeration)).put((y + 1) * 0.25f);
               
                tBuffer.put((x + 1) * 0.25f).put((float) (map[x + 1][y + 1] * heightmapExaggeration)).put((y + 1) * 0.25f);
                tBuffer.put((x + 1) * 0.25f).put((float) (map[x + 1][y] * heightmapExaggeration)).put(y * 0.25f);
                tBuffer.put(x * 0.25f).put((float) (map[x][y + 1] * heightmapExaggeration)).put((y + 1) * 0.25f);                  
             }
          }
         
          cBuffer.flip();
          vBuffer.flip();
          tBuffer.flip();
           
          int vbo_vertex_handle = GL15.glGenBuffers();
          GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_vertex_handle);
          GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vBuffer, GL15.GL_STATIC_DRAW);
          GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
   
          int vbo_color_handle = GL15.glGenBuffers();
          GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_color_handle);
          GL15.glBufferData(GL15.GL_ARRAY_BUFFER, cBuffer, GL15.GL_STATIC_DRAW);
          GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
         
          int vbo_tex_coord_handle = GL15.glGenBuffers();
          GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_tex_coord_handle);
          GL15.glBufferData(GL15.GL_ARRAY_BUFFER, tBuffer, GL15.GL_STATIC_DRAW);
          GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
         
          GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_vertex_handle);
          GL11.glVertexPointer(vertex_size, GL11.GL_FLOAT, 0, 0l);
   
          GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_color_handle);
          GL11.glColorPointer(color_size, GL11.GL_FLOAT, 0, 0l);
         
          GL11.glBindTexture(GL11.GL_TEXTURE_2D, floor.getTextureID());
          GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_tex_coord_handle);
          GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
          GL11.glTexCoordPointer(texture_size, GL11.GL_FLOAT, 0, 0l);
         
          GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
          GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
          GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY_POINTER);
   
          while (!Display.isCloseRequested()) {
   
             preRender();
             render();
   
             Display.update();
             Display.sync(60 /* desired fps */);
   
             frames++;
             if ((System.currentTimeMillis() - time) >= 1000) {
                Display.setTitle(" FPS: " + (int) ((frames * 1000) / (System.currentTimeMillis() - time)));
                time = System.currentTimeMillis();
                frames = 0;
             }
          }
          GL15.glDeleteBuffers(vbo_vertex_handle);
          GL15.glDeleteBuffers(vbo_color_handle);
          GL15.glDeleteBuffers(vbo_tex_coord_handle);
         
          floor.release();
         
          GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
          GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
          GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY_POINTER);
          Display.destroy();
       }
   
       void preRender() {
          glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
          // GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
          glMatrixMode(GL_PROJECTION);
          glLoadIdentity();
   
          GLU.gluPerspective(45.0f, ((float) w / (float) h), 0.1f, 100.0f); // fix na błąd z kamerą
   
          glMatrixMode(GL_MODELVIEW);
          glLoadIdentity();
       }
   
       void render() {
          GL11.glClearColor(1, 1, 1, 1);
   
          Camera.acceptInput(0.6f);
          Camera.apply();
   
          //GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, (Size*Size)*2);
          //floor.bind();
          /*for (int x = 0; x < (Size*Size)*2; x++) {
             glDrawArrays(GL_TRIANGLES, x * 3, 3);
          }*/

          glDrawArrays(GL_TRIANGLES, 0, ((Size*Size)*2)*3);
       }
   
       public void start() throws Exception {
          initContext();
          renderLoop();
       }


EDIT:
Resolved
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1278 views)
2018-06-10 19:43:48

EgonOlsen (1146 views)
2018-06-10 19:43:44

EgonOlsen (881 views)
2018-06-10 19:43:20

DesertCoockie (1290 views)
2018-05-13 18:23:11

nelsongames (1106 views)
2018-04-24 18:15:36

nelsongames (1337 views)
2018-04-24 18:14:32

ivj94 (2077 views)
2018-03-24 14:47:39

ivj94 (1230 views)
2018-03-24 14:46:31

ivj94 (2188 views)
2018-03-24 14:43:53

Solater (796 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!