Results 1 to 4 of 4
Like Tree2Likes
  • 1 Post By typedef
  • 1 Post By gimbal2

Thread: Where to Study from here.

  1. #1
    robcardiv is offline Member
    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    Default Where to Study from here.

    I've slowly been studying C++ and Java. I have been focusing on Java recently.
    Ill post a little code, to show how basic my understandings are. Its pretty basic.

    I would like some advice, about what topics I should focus on next.
    I was trying to understand Textures and OpenGL with Java. but the tutorials I find cover such a horribly broad area X_x.

    Basically I can get a window up, initialize openGL, and draw many repeating blocks on my screen.
    I dont specifically care about minecraft. but I would like to learn how to get Many many blocks on the screen

    and how to apply more than one texture to a block. I cant seem to load two textures at a time without errors.
    I have a dumb while loop that includes a few For loops that repeat the blocks.

    I guess I should learn how to use Arrays to automate the block process ? Im not sure. I started reading about object buffers, but im not sure.

    If anyone has any tips as to the direction my program is going, and why its really bad. I would love to read the tips.
    I Trimmed the code down, to the important areas.
    ==============

    public static void initDisplay()
    {
    try {
    Display.setFullscreen(true);
    Display.setVSyncEnabled(true); // Drastically effects updates per second, Camera movement lowers by 98%
    DisplayMode mode = Display.getDesktopDisplayMode();
    //Display.setDisplayMode(mode);
    Display.create();
    } catch (LWJGLException ex) {
    Logger.getLogger(GearBoxBeta.class.getName()).log( Level.SEVERE, null, ex);
    }
    }

    private static void gameLoop()
    {

    Camera cam1 = new Camera();
    cam1.initView();
    Mouse.setGrabbed(true);

    Block block1 = new Block(0f,0f,0f);
    //BlockTop blocktop1 = new BlockTop(0f,0f,0f);

    while(!Display.isCloseRequested())
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //FPS-Frame Clear
    glLoadIdentity(); //Locational transform information
    cam1.controlerUpdate();
    cam1.updateView();




    block1.x = 5; block1.y = 0; block1.z = 5; block1.copy();
    block1.x = 6; block1.y = 0; block1.z = 5; block1.copy();
    block1.x = 7; block1.y = 0; block1.z = 5; block1.copy();
    block1.x = 8; block1.y = 0; block1.z = 5; block1.copy();
    block1.x = 9; block1.y = 0; block1.z = 5; block1.copy();

    block1.x = 5; block1.y = 0; block1.z = 6; block1.copy();
    block1.x = 6; block1.y = 0; block1.z = 6; block1.copy();
    block1.x = 7; block1.y = 0; block1.z = 6; block1.copy();
    block1.x = 8; block1.y = 0; block1.z = 6; block1.copy();
    block1.x = 9; block1.y = 0; block1.z = 6; block1.copy();



    block1.y= -1;
    for(int i2 = 0; i2 < 50; i2++) { block1.z=i2; block1.row(); }
    //block1.row();

    Display.update();
    }
    ==================END OF CLASS - Main

    public class Block {
    float x; float y; float z;
    float x2; float y2; float z2;
    Texture grass = loadTexture("grass");



    public Block(float a, float b, float c)
    {
    this.x = a; this.y = b; this.z = c;

    }

    public void copy()
    {
    this.x2 = x + 1f ; this.y2 = y +1f ; this.z2 = z +1f ;

    glPushMatrix();
    glBegin(GL_QUADS);

    grass.bind();

    glColor3f(.0f,.8f,.0f); // top
    glTexCoord2f(x,x); glVertex3f( x2, y2,z);
    glTexCoord2f(x,x2); glVertex3f(x, y2,z);
    glTexCoord2f(x2,x2); glVertex3f(x, y2, z2);
    glTexCoord2f(x2,x); glVertex3f( x2, y2, z2);

    glColor3f(.10f,0.1f,0.10f); //bottom
    glTexCoord2f(x,x); glVertex3f( x2,y, z2);
    glTexCoord2f(x,x2); glVertex3f(x,y, z2);
    glTexCoord2f(x2,x2); glVertex3f(x,y,z);
    glTexCoord2f(x2,x); glVertex3f( x2,y,z);


    glColor3f(.35f,.25f,.0f); //front
    glTexCoord2f(x,x); glVertex3f( x2, y2, z2);
    glTexCoord2f(x,x2); glVertex3f(x, y2, z2);
    glTexCoord2f(x2,x2); glVertex3f(x,y, z2);
    glTexCoord2f(x2,x); glVertex3f( x2,y, z2);

    glColor3f(0.35f,0.25f,.0f); //back
    glTexCoord2f(x,x); glVertex3f( x2,y,z);
    glTexCoord2f(x,x2); glVertex3f(x,y,z);
    glTexCoord2f(x2,x2); glVertex3f(x, y2,z);
    glTexCoord2f(x2,x); glVertex3f( x2, y2,z);

    glColor3f(.35f,0.25f,0.0f); //left
    glTexCoord2f(x,x); glVertex3f( x2, y2,z);
    glTexCoord2f(x,x2); glVertex3f( x2, y2, z2);
    glTexCoord2f(x2,x2); glVertex3f( x2,y, z2);
    glTexCoord2f(x2,x); glVertex3f( x2,y,z);

    glColor3f(.35f,0.25f,.0f); //right
    glTexCoord2f(x,x); glVertex3f(x, y2, z2);
    glTexCoord2f(x,x2); glVertex3f(x, y2,z);
    glTexCoord2f(x2,x2); glVertex3f(x,y,z);
    glTexCoord2f(x2,x); glVertex3f(x,y, z2);

    glEnd();
    glPopMatrix();
    //set set set
    // this.x2 = 0 ; this.y2 = 0 ; this.z2 = 0 ; x = 0; y = 0; z = 0;
    }


    public Texture loadTexture(String key)
    {
    try {
    // return TextureLoader.getTexture("png", new FileInputStream(new File("res/" + key + ".png"))); // bennybox data
    return TextureLoader.getTexture("png", ResourceLoader.getResourceAsStream("res/" + key + ".png")); // lwjgl site data
    } catch (IOException ex) {
    Logger.getLogger(GearBoxBeta.class.getName()).log( Level.SEVERE, null, ex);
    }
    return null;
    }

    public void row()
    {
    for(int i = 0; i < 50; i++) { this.x=i; copy(); }
    }
    }
    =================END OF CLASS - Block

    public class Camera {

    // float fov; float aspect; float nearClip; float farClip;
    float x=0; float y=0; float z= 0;
    float rx=0; float ry=0 ; float rz=0;


    public Camera()
    {
    initProjection();
    }

    public static void initProjection()
    {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(70,1280f/720f,.2f,1000);
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_CULL_FACE);


    }

    public void initView()
    {
    x = -2; y = -2; z = -8;
    glRotatef(rx,1,0,0);
    glRotatef(ry ,0,1,0);
    glRotatef(rz,0,0,1);
    glTranslatef(x,y,z);
    }

    public void updateView()
    {
    glRotatef(rx,1,0,0);
    glRotatef(ry ,0,1,0);
    glRotatef(rz,0,0,1);
    glTranslatef(x,y,z);
    }

    public void walk(float speed) { z += speed * Math.sin(Math.toRadians(ry + 90)); x += speed * Math.cos(Math.toRadians(ry + 90 )); }
    public void strafe(float speed) { x += speed * Math.sin(Math.toRadians(ry + 90)); z += speed * Math.cos(Math.toRadians(ry - 90 )); }
    public void rotate(float speed) { ry += speed; }
    public void jump(float speed) { y += speed; }
    public void pitch(float speed) { rx += speed; }

    public void mRotate(float DX) { ry += DX * .4f ; }
    public void mPitch(float DY) { rx -= DY * .4f ; }


    public void controlerUpdate()
    {
    if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {Display.destroy(); }
    if(Keyboard.isKeyDown(Keyboard.KEY_W)) { walk(.1f);}
    if(Keyboard.isKeyDown(Keyboard.KEY_S)) { walk(-.1f);}
    if(Keyboard.isKeyDown(Keyboard.KEY_A)) { strafe(.1f);}
    if(Keyboard.isKeyDown(Keyboard.KEY_D)) { strafe(-.1f);}
    if(Keyboard.isKeyDown(Keyboard.KEY_E)) { rotate(3f);}
    if(Keyboard.isKeyDown(Keyboard.KEY_Q)) { rotate(-3f);}
    if(Keyboard.isKeyDown(Keyboard.KEY_R)) { pitch(-2f);}
    if(Keyboard.isKeyDown(Keyboard.KEY_F)) { pitch(2f);}
    if(Keyboard.isKeyDown(Keyboard.KEY_C)) { jump(.1f);}
    if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { jump(-.1f);}

    mRotate(Mouse.getDX());
    mPitch(Mouse.getDY());
    }
    }

  2. #2
    typedef is offline Member
    Join Date
    Feb 2014
    Posts
    52
    Rep Power
    0

    Default Re: Where to Study from here.

    I'll probably get deeply flamed for what I'm about to say but w/e here goes.
    First I might as well say this before I even begin, I didn't read your code, its kinda long.
    Second I find your thread title misleading as 1) its not a question 2) you seem to have your hands full already learning something pretty steep - computer graphics specifically OpenGL which maybe it's just me but I find to be pretty complicated in and of itself. I've heard it been said that learning OpenGL/Directx is like learning a new programming language altogether.

    As for my advice,
    If your serious about doing OpenGL in the long term with performance squeezed out the last drop you should really invest in just learning OpenGL in C++ not some binding (JOGL or LWJGL). Someone correct me if I'm wrong but last I heard it seems that the performance penalty of using a binding for graphics is still pretty significant for the the ethusiast. If so maybe i'll have to look into it myself....

    As for what to look into next maybe you should learn some more of the standard Java Libraries. If you haven't learned how to build GUI's learn Swing. If you don't know generics (you probably got this already) learn em. Learn some of the collections from the collection api (java.util package). Taking a moment to learn other streams aside from Scanner and PrintWriter also wouldn't hurt.
    Some libraries/stuff I'd recommend:
    - Learn to use a Logger
    - Learn to use the Preferences API (java.util.prefs.Preference or the older java.util.Properties)
    - Learn multi-threading.
    - Learn regular expressions java.util.regex
    - XML file processing can also be pretty beneficial
    - Network/Database APIs.

    Got many of these in your belt already and don't know what to do with it? try some of these:
    Martyr2&#39;s Mega Project Ideas List! - Share Your Project | Dream.In.Code
    gimbal2 likes this.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,029
    Rep Power
    6

    Default Re: Where to Study from here.

    *prepares the blowtorch*

    Quote Originally Posted by typedef View Post
    I've heard it been said that learning OpenGL/Directx is like learning a new programming language altogether.
    Pretty much, yeah. You have to speak the languages of Math and graphics programming.

    Someone correct me if I'm wrong but last I heard it seems that the performance penalty of using a binding for graphics is still pretty significant for the the ethusiast. If so maybe i'll have to look into it myself....
    Of course there is a penalty, but it is not significant unless you do the wrong thing and use immediate mode rendering, which is already a no-no when you use OpenGL through C++. If you use buffers then the number of OpenGL calls you need to do will be minimal and thus there is no real overhead from using JNI.


    Can't fault most of your reply though, good job!
    typedef likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: Where to Study from here.

    Burn, typedef, burn! I agree with you about learning the standard Java libraries.

    Quote Originally Posted by robcardiv View Post
    I was trying to understand Textures and OpenGL with Java. but the tutorials I find cover such a horribly broad area X_x.
    You might want to check out the Pro Java 6 3D Game Development book, in particular Chapter 1. Introducing Java 3D and Chapter 15. Two JOGL Programming Frameworks. Heck, just read the entire book.

    Quote Originally Posted by robcardiv View Post
    I've slowly been studying C++ and Java. I have been focusing on Java recently.
    It depends on your objectives. With Java, how well-versed are you with the topics covered at The Really Big Index ? This goes back to what typedef wrote about learning "some more of the standard Java Libraries".

    Btw, do wrap your code using [code] tags, e.g.,
    [code]
    ... your code goes here ...
    [/code]

    This makes is a lot easier for others to read your code.

Similar Threads

  1. Should I study both PHP and JavaScript at the same time?
    By Captain Forge in forum Forum Lobby
    Replies: 0
    Last Post: 02-06-2013, 01:33 AM
  2. Alkitab Bible Study 2.8
    By java software in forum Java Software
    Replies: 0
    Last Post: 01-30-2012, 05:39 PM
  3. jsp study materials
    By gautamshaw in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 08-28-2009, 03:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •