Jump to content

  • Log In with Google      Sign In   
  • Create Account

please help me!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Adam West   Members   -  Reputation: 219

Like
0Likes
Like

Posted 29 March 2012 - 02:28 AM

hey there,
im currently in a bit of trouble with my code:
firstly, the skybox is not showing up on my screen, just a grey overlay.
Also, i cant assign one texture to different objects.
Lastly, Why is my box being cut off where it is ( yes that's a box!)
please help me,
CODE:

main.h
//Include STD headers
#ifndef MAIN_H
#define MAIN_H

#include<GL/glew.h>
#include<GL/glfw.h>
#include<GL/freeglut.h>
#include <vector>
#include<algorithm>
#include <fstream>
#include<cstdio>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <SFML/Graphics.hpp>
#include <SOIL.h>

//Include GLM
#include <glm/glm.hpp>
using namespace std;
extern GLuint loadShader(const char* vertex_file_path, const char* fragment_file_path);
extern int loadTexture(const char* texfilename,GLuint textureObject);
extern void deleteTexture(GLuint textureObject);
extern void InitializeWindow();
extern void shutdown();
#endif

skybox.h
#include "main.h"

class skybox
{
public:
void initSkybox( const char* xpos, const char* xneg, const char* ypos, const char* yneg, const char* zpos, const char* zneg);
void skyboxVBO();
void drawSkybox();
void destroySkybox();
	  //constants for the skybox
};
texture.cpp
#include "3dsloader.h"

int loadTexture(const char* texfilename,GLuint textureObject) //load bitmap and convert to texture
{
glGenTextures(1,&textureObject); // allocate memory for one texture
glBindTexture( GL_TEXTURE_2D,textureObject); // use our newest texture

textureObject = SOIL_load_OGL_texture(texfilename,SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_MIPMAPS);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // give the best result for texture magnification
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //give the best result for texture minification
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); // don't repeat texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // don't repeat texture
return textureObject;
}

//MAY NOT WORK PROPERLY
void deleteTexture(GLuint textureObject)
{
glDeleteTextures(1,&textureObject);
}
shader.cpp
#include "3dsloader.h"

int loadTexture(const char* texfilename,GLuint textureObject) //load bitmap and convert to texture
{
glGenTextures(1,&textureObject); // allocate memory for one texture
glBindTexture( GL_TEXTURE_2D,textureObject); // use our newest texture

textureObject = SOIL_load_OGL_texture(texfilename,SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_MIPMAPS);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // give the best result for texture magnification
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //give the best result for texture minification
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); // don't repeat texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // don't repeat texture
return textureObject;
}

//MAY NOT WORK PROPERLY
void deleteTexture(GLuint textureObject)
{
glDeleteTextures(1,&textureObject);
}
skybox.cpp
#include "skybox.h"
GLuint skyboxShaderID;
GLuint skytexture;
GLint vertex;
void skybox::initSkybox(const char* xpos, const char* xneg, const char* ypos, const char* yneg, const char* zpos, const char* zneg)
{

glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_CUBE_MAP);
glGenTextures(1,&skytexture);
skytexture = SOIL_load_OGL_cubemap(
  xpos,
  xneg,
  ypos,
  yneg,
  zpos,
  zneg,
  SOIL_LOAD_RGB,
  SOIL_CREATE_NEW_ID,
  0
  );
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

}

void skybox::destroySkybox()
{
glDeleteTextures(1, &skytexture);
}


GLuint skyboxVertexBuffer;
GLuint skyboxIndexBuffer;
void skybox::skyboxVBO()
{
glGenBuffers(1, &skyboxVertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, skyboxVertexBuffer);

GLfloat skybox_vertex_data[] =
{
  -1.0, -1.0,  1.0,
  1.0, -1.0,  1.0,
  -1.0,  1.0,  1.0,
  1.0,  1.0,  1.0,
  -1.0, -1.0, -1.0,
  1.0, -1.0, -1.0,
  -1.0,  1.0, -1.0,
  1.0,  1.0, -1.0,
};

glBufferData(GL_ARRAY_BUFFER, sizeof(skybox_vertex_data), skybox_vertex_data, GL_STATIC_DRAW);
glGenBuffers(1, &skyboxIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, skyboxIndexBuffer);

GLubyte indices[14] = {0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1};
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
}
void skybox::drawSkybox()
{
glClearColor(0.5f, 0.5f, 0.5f, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
skyboxShaderID = loadShader("assets/skybox/skybox.vert","assets/skybox.skybox.frag");
glUseProgram(skyboxShaderID);
glDisable(GL_DEPTH_TEST);   // skybox should be drawn behind anything else
glBindTexture(GL_TEXTURE_CUBE_MAP,skytexture);

glBindBuffer(GL_ARRAY_BUFFER,skyboxVertexBuffer);
glVertexAttribPointer(skyboxShaderID, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(skyboxShaderID);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, skyboxIndexBuffer);
glDrawElements(GL_TRIANGLE_STRIP, 14, GL_UNSIGNED_BYTE, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
}
main.cpp
#include "main.h"
#include "3dsloader.h"
#include "camera.h"
#include "skybox.h"
bool mousein= false;
GLuint programID;
void lighting();
void initRendering();
void drawScene();
void mainLoop();
FPSCamera * camera;
Object* testcube;
GLuint testObjTex;
skybox* sky;

int main(int argc, char **argv)
{
bool running = true;

InitializeWindow();

sky->initSkybox("assets/skybox/citystorm/xpos.jpg","assets/skybox/citystorm/xneg.jpg","assets/skybox/citystorm/ypos.jpg","assets/skybox/citystorm/yneg.jpg","assets/skybox/citystorm/zpos.jpg","assets/skybox/citystorm/zneg.jpg");
sky->skyboxVBO();
testcube = new Object("test.3ds");

testcube->CreateVBO();
initRendering();

//shader setup
programID = loadShader("emptyshader.vert","bokehDOF.frag");
mainLoop();


return 0;
}
void initRendering()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
// Enable lighting and set the position of the light
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
GLfloat pos[] = { 0.0, 4.0, 4.0 };
glLightfv(GL_LIGHT0, GL_POSITION, pos);

}

void mainLoop(void)
{
// the time of the previous frame
double old_time = glfwGetTime();
// this just loops as long as the program runs
while(1)
{
  // KEY EVENTS 1
  // escape to quit,

  //use shader
  glUseProgram(programID);
  camera->updateCamera();

  if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS)
   break;

  if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
   {
	mousein = true;
  glfwDisable(GLFW_MOUSE_CURSOR);

  }
   if(glfwGetKey('P') == GLFW_PRESS)
   {
	mousein=false;
	glfwEnable(GLFW_MOUSE_CURSOR);
  
   }
  camera->Control(0.2,0.2,mousein);
  // draw the figure

  drawScene();


  // swap back and front buffers
  glfwSwapBuffers();

}
}

void drawScene()
{
//clear info from last draw
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//skybox for scene
sky->drawSkybox();
// ADD SCENE OBJECTS TO RENDER HERE


//model loading and stuff
glEnable(GL_TEXTURE_2D);
loadTexture("texture.jpg",testObjTex);
testcube->Draw();
glDisable(GL_TEXTURE_2D);
glLoadIdentity();
};

void shutdown()
{
glfwTerminate();
sky->destroySkybox();
delete sky;
sky= NULL;
deleteTexture(testObjTex);
delete testcube;
testcube = NULL;
delete camera;
camera = NULL;
exit(1);
}


all input is welcome as i am in a rush to get this working!

Attached Thumbnails

  • Untitled.png


Sponsor:

#2 Rld_   Members   -  Reputation: 1466

Like
-1Likes
Like

Posted 29 March 2012 - 04:37 AM

Are you sure, in case if your skybox, that the shader is correct?

About the box, seems like your far clipping plane is causing this. Have you tried moving the box towards the camera and see if it gets in view? If you rotate it, will it be cut off at the same place? Does the model always look like that no matter what orientation?

If you, for example, treat the skybox the same as any other model, your skybox might also be the victim of your clipping plane.

If you're using a model loader. Are you sure the exported model is correct? Is the data you read in correct? Do you pass all the correct data for rendering?

Seeing your past posts, I think you should take a step down and try to understand what you are doing here, because I think you're rather clueless on what is going on right now. It might be a good idea to get a grip on the fixed function pipeline, the basics at least, to learn some basic opengl. You can move to shaders later.

#3 Lauris Kaplinski   Members   -  Reputation: 841

Like
0Likes
Like

Posted 02 April 2012 - 05:26 AM

skyboxShaderID = loadShader("assets/skybox/skybox.vert","assets/skybox.skybox.frag");
You are creating new shader object each frame (if I understand your code correctly).
glVertexAttribPointer(skyboxShaderID, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(skyboxShaderID);
You are using shader ID as attribute index here.
Lauris Kaplinski

First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS