Title sounds like a stupid question at first but this is baffeling me and I couldn't think of a concise way to put it.
Anyways, here is the code I am using:
public class OreSword extends ItemSword{
public OreSword(SWORDTYPES sword)
{
super(sword.getMaterial());
setUnlocalizedName(RefStrings.MODID + "_" + sword.getName());
setTextureName(RefStrings.MODID + ":" + sword.getName());
//setCreativeTab(CreativeTabs.tabCombat);
sword.setSword(this);
}
public boolean hitEntity(ItemStack sword, EntityLivingBase target, EntityLivingBase self)
{
System.out.println("this is my override");
sword.damageItem(1, self);
if(sword.getUnlocalizedName() == SWORDTYPES.COAL.getSword().getUnlocalizedName())
{
System.out.println("this is my sword");
target.setFire(100);
}
return true;
}
public static enum SWORDTYPES
{
COAL("CoalSword", 1, 131, 4.0F, 1.0F, 5),
DIAMOND("DiamondSword", 3, 1200, 8.0F, 3.0F, 30),
EMERALD("EmeraldSword", 3, 2300, 8.0F, 4.0F, 10),
GOLD("GoldSword", 0, 25, 10.0F, 1.0F, 12),
IRON("IronSword", 2, 131, 6.0F, 2.0F, 14),
LAPIS("LapisSword", 1, 131, 4.0F, 1.0F, 44),
QUARTZ("QuartzSword", 3, 131, 8.0F, 3.0F, 10),
REDSTONE("RedstoneSword", 2, 131, 6.0F, 2.0F, 14);
private String name;
/*private int hLevel;
private int mUse;
private float effic;
private float damage;
private int ench;*/
private ToolMaterial mat;
private OreSword sword;
private SWORDTYPES(String name, int hLevel, int mUse, float effic, float damage, int ench)
{
this.name = name;
this.mat = EnumHelper.addToolMaterial(name, hLevel, mUse, effic, damage, ench);
}
public String getName(){return name;}
public ToolMaterial getMaterial(){return mat;}
public void setSword(OreSword sword){this.sword = sword;}
public OreSword getSword(){return sword;}
}
}
When I run this code it does output the line "this is my override" but it never prints out the line "this is my sword"
The sword I am testing with in game is the correct sword, I have tested this in creative so the sword doesn't take any damage, and in survival with the sword taking damage.
If someone can explain to me either what I should be doing to check an item or what I might be missing in my implementation I would appreciate it.
Always use public boolean equals(Object obj) when comparing two strings in Java.
if(sword.getUnlocalizedName().equals(SWORDTYPES.COAL.getSword().getUnlocalizedName()))
Also, if they are not equal a nice trick is to try and print them to see what makes them unequal, for example;
System.out.println("sword: " + sword.getUnlocalizedName());
System.out.println("SWORDTYPES: " + SWORDTYPES.COAL.getSword().getUnlocalizedName());
Related
I'm trying to make a demo using optaplanner: there are some schemes, each scheme has attribute of gain and cost, and a scheme may conflict with one or more other schemes. The question is to find out a group of schemes which match following constraints:
hard constraint: selected schemea may not conflict with each other in this group
soft constraint: make the difference between total gain and total cost as high as possible
I built following code and try to resolve the question:
#PlanningEntity
#Data
#NoArgsConstructor
public class Scheme {
#PlanningId
private String id;
private int gain;
private int cost;
#PlanningVariable(valueRangeProviderRefs = {"validRange"})
// when valid is ture means this scheme will be selected into the solution group
private Boolean valid;
private Set<String> conflicts = new HashSet<>();
public void addConflict(String id) {
conflicts.add(id);
}
public Scheme(String id, int gain, int cost, String[] conflicts) {
this.id = id;
this.gain = gain;
this.cost = cost;
for (String s : conflicts) {
addConflict(s);
}
}
}
#PlanningSolution
public class SchemeSolution {
private HardSoftScore score;
private List<Scheme> schemeList;
#ProblemFactCollectionProperty
#ValueRangeProvider(id = "validRange")
public List<Boolean> getValidRange() {
return Arrays.asList(Boolean.FALSE, Boolean.TRUE);
}
#PlanningScore
public HardSoftScore getScore() {
return score;
}
public void setScore(HardSoftScore score) {
this.score = score;
}
#PlanningEntityCollectionProperty
public List<Scheme> getSchemeList() {
return schemeList;
}
public void setSchemeList(List<Scheme> schemeList) {
this.schemeList = schemeList;
}
}
And the constraint rule as below:
rule "conflictCheck"
when
Boolean(this==true) from accumulate (
$schs: List() from collect (Scheme(valid==true)),
init(boolean cfl = false;Set cfSet = new HashSet();List ids = new ArrayList()),
action(
for(int i = 0; i < $schs.size(); ++i) {
Scheme sch = (Scheme)$schs.get(i);
cfSet.addAll(sch.getConflicts());
ids.add(sch.getId());
}
for( int i = 0; i < ids.size(); ++i) {
String id = (String)ids.get(i);
if(cfSet.contains(id)) {
cfl = true;
return true;
}
}
),
result(cfl)
)
then
scoreHolder.addHardConstraintMatch(kcontext, -10000);
end
rule "bestGain"
when
$gc : Number() from
accumulate(
Scheme(valid==true, $gain : gain, $cost: cost),
sum($gain - $cost)
)
then
scoreHolder.addSoftConstraintMatch(kcontext, $gc.intValue());
end
Then I constructed three schemes as input of the test. Oddly, I found that optaplanner can't get the best solution, and different input orders produce different solutions.
When I set input as following:
private static List<Scheme> getSchemes() {
List<Scheme> ret = new ArrayList();
ret.add(new Scheme("S1", 5, 2, new String[]{"S3"}));
ret.add(new Scheme("S2", 3, 1, new String[]{"S3"}));
ret.add(new Scheme("S3", 10, 4, new String[]{"S1", "S2"}));
return ret;
}
the output is :
0hard/5soft
Scheme(id=S1, gain=5, cost=2, valid=true, conflicts=[S3])
Scheme(id=S2, gain=3, cost=1, valid=true, conflicts=[S3])
Scheme(id=S3, gain=10, cost=4, valid=false, conflicts=[S1, S2])
And when I set input as following:
private static List<Scheme> getSchemes() {
List<Scheme> ret = new ArrayList();
ret.add(new Scheme("S3", 10, 4, new String[]{"S1", "S2"}));
ret.add(new Scheme("S1", 5, 2, new String[]{"S3"}));
ret.add(new Scheme("S2", 3, 1, new String[]{"S3"}));
return ret;
}
I get the best solution and the output is :
0hard/6soft
Scheme(id=S3, gain=10, cost=4, valid=true, conflicts=[S1, S2])
Scheme(id=S1, gain=5, cost=2, valid=false, conflicts=[S3])
Scheme(id=S2, gain=3, cost=1, valid=false, conflicts=[S3])
Could anyone help me about it?
I'm working on making a small G4P GUI as test for Arduino communication.
Control Panel
So it’s just basic: when X button is pressed, send Y to the console, and the Arduino does whatever with Y, but the Processing console is just full of garbage.
The trash
Arduino wiring
Here is the code for the Arduino:
int rLED = 7;
int gLED = 8;
int R = 11;
int G = 12;
int B = 13;
void setup() {
pinMode(rLED, OUTPUT);
pinMode(gLED, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
char state = Serial.read();
if(state == '1')
{
digitalWrite (rLED, HIGH);
}
if(state == '2')
{
digitalWrite (rLED, LOW);
}
if(state == '3')
{
digitalWrite (gLED, HIGH);
}
if(state == '4')
{
digitalWrite (gLED, LOW);
}
}
}
Here is the code for Processing:
import processing.serial.*;
// Need G4P library
import g4p_controls.*;
Serial myPort;
public void setup() {
size(480, 320, JAVA2D);
createGUI();
customGUI();
// Place your setup code here
myPort = new Serial(this, "COM4", 9600);
}
public void draw() {
background(230);
}
public void handleButtonEvents(GButton button, GEvent event) {
if (button == rLED && event == GEvent.CLICKED) {
myPort.write('1');
delay(100);
myPort.write('2');
}
if (button == button1 && event == GEvent.CLICKED) {
myPort.write('3');
delay(100);
myPort.write('4');
}
}
// Use this method to add additional statements
// to customise the GUI controls
public void customGUI() {
}
Here is the code for the GUI (Processing):
public void Red_Blink(GButton source, GEvent event) { // _CODE_:rLED:951221:
println("rLED - GButton >> GEvent." + event + " # " + millis());
} // _CODE_:rLED:951221:
public void Green_Blink(GButton source, GEvent event) { // _CODE_:button1:443069:
println("button1 - GButton >> GEvent." + event + " # " + millis());
} // _CODE_:button1:443069:
public void Red_int(GCustomSlider source, GEvent event) { // _CODE_:Red:702179:
println("custom_slider1 - GCustomSlider >> GEvent." + event + " # " + millis());
} // _CODE_:Red:702179:
public void Green_int(GCustomSlider source, GEvent event) { // _CODE_:Green:645891:
println("custom_slider2 - GCustomSlider >> GEvent." + event + " # " + millis());
} // _CODE_:Green:645891:
public void Blue_int(GCustomSlider source, GEvent event) { // _CODE_:Blue:372420:
println("Blue - GCustomSlider >> GEvent." + event + " # " + millis());
} // _CODE_:Blue:372420:
// Create all the GUI controls.
// autogenerated do not edit
public void createGUI() {
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.GOLD_SCHEME);
G4P.setCursor(ARROW);
surface.setTitle("Controll panel ");
tittle = new GLabel(this, 180, 10, 150, 30);
tittle.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
tittle.setText("Controll arduino");
tittle.setTextBold();
tittle.setLocalColorScheme(GCScheme.BLUE_SCHEME);
tittle.setOpaque(false);
rLED = new GButton(this, 60, 80, 80, 30);
rLED.setText("blink red LED");
rLED.setLocalColorScheme(GCScheme.RED_SCHEME);
rLED.addEventHandler(this, "Red_Blink");
button1 = new GButton(this, 150, 80, 80, 30);
button1.setText("blink greed LED");
button1.setLocalColorScheme(GCScheme.GREEN_SCHEME);
button1.addEventHandler(this, "Green_Blink");
Red = new GCustomSlider(this, 20, 140, 440, 40, "grey_blue");
Red.setShowValue(true);
Red.setLimits(150, 0, 255);
Red.setNumberFormat(G4P.INTEGER, 0);
Red.setLocalColorScheme(GCScheme.RED_SCHEME);
Red.setOpaque(false);
Red.addEventHandler(this, "Red_int");
Green = new GCustomSlider(this, 18, 200, 440, 40, "grey_blue");
Green.setShowValue(true);
Green.setLimits(50, 0, 255);
Green.setNumberFormat(G4P.INTEGER, 0);
Green.setLocalColorScheme(GCScheme.GREEN_SCHEME);
Green.setOpaque(false);
Green.addEventHandler(this, "Green_int");
label1 = new GLabel(this, 200, 130, 80, 20);
label1.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
label1.setText("Red");
label1.setLocalColorScheme(GCScheme.BLUE_SCHEME);
label1.setOpaque(false);
label2 = new GLabel(this, 200, 190, 80, 20);
label2.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
label2.setText("Green");
label2.setLocalColorScheme(GCScheme.BLUE_SCHEME);
label2.setOpaque(false);
Blue = new GCustomSlider(this, 20, 260, 440, 40, "grey_blue");
Blue.setShowValue(true);
Blue.setLimits(150, 0, 255);
Blue.setNumberFormat(G4P.INTEGER, 0);
Blue.setLocalColorScheme(GCScheme.BLUE_SCHEME);
Blue.setOpaque(false);
Blue.addEventHandler(this, "Blue_int");
label3 = new GLabel(this, 200, 250, 80, 20);
label3.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
label3.setText("Blue");
label3.setLocalColorScheme(GCScheme.BLUE_SCHEME);
label3.setOpaque(false);
}
// Variable declarations
// autogenerated do not edit
GLabel tittle;
GButton rLED;
GButton button1;
GCustomSlider Red;
GCustomSlider Green;
GLabel label1;
GLabel label2;
GCustomSlider Blue;
GLabel label3;
The problem seems to be in the Processing code in the setup() function.
Try this:
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
I've been having problems with my php code. I seem to be getting an error from #mysql_query().
Here's my code for php:
<?php
// A simple PHP script demonstrating how to connect to MySQL.
// Press the 'Run' button on the top to start the web server,
// then click the URL that is emitted to the Output tab of the console.
$servername = getenv('IP');
$username = getenv('C9_USER');
$passwordp = "";
$database = "game_database";
$dbport = 3306;
// Create connection
mysql_connect($servername, $username, $passwordp, $dbport)or die("Cant Connect to server");
mysql_select_db($database) or die("Cant connect to database");
// Check connection
$Email = $_REQUEST["Email"];
$Password= $_REQUEST["Password"];
if (!$Email || !$Password){
echo"Email or password must be used";
}
else{
$SQL = "SELECT * FROM 'users' WHERE Email = '" . $Email ."'";
$result_id = #mysql_query($SQL) or die("Database Error");
$Total = mysql_num_rows($result_id);
if ($Total){
$datas = #mysql_fetch_array($result_id);
if (strcmp($Password, $datas["Password"])){
$sql2 = "SELECT Characters FROM users WHERE Email = '" . $Email ."'";
$result_id2 = #mysql_query($sql2) or die("Database Error!!!");
while ($row = mysql_fetch_array($result_id2)){
echo $row ["Characters"];
echo ":";
echo "Success";
}
}
else{
echo "WrongPassword";
}
}else {
echo "NameDoesNotExist";
}
}
?>
Here's my code for C#:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LoginScript : MonoBehaviour {
#region Variables
//Static Variables
public static string Email = "";
public static string Password = "";
//Private Variables
private string createAccountUrl = "https://credmanager-rowanharley.c9.io/createaccount.php";
private string loginUrl = "https://credmanager-rowanharley.c9.io/loginaccount.php";
private string ConfirmPass= "";
private string CreateEmail = "";
private string CreatePassword = "";
//Public Variables
public string currentMenu = "Login";
//GUI test section
public float X;
public float Y;
public float Width;
public float Height;
#endregion
// Use this for initialization
void Start () {
}
void OnGUI(){
//If current menu is = login call login screen
if (currentMenu == "Login"){
LoginGUI();
}
//If current menu is = Create Account call CreateAccount screen
else if(currentMenu == "CreateAccount"){
CreateAccountGUI();
}
}
//This method will login to accounts
void LoginGUI(){
GUI.Box (new Rect (210, 15, 300, 300), "Login");
if (GUI.Button (new Rect (250, 275, 105, 35), "Register Now!!!")) {
currentMenu = "CreateAccount";
}
if (GUI.Button (new Rect (370, 275, 105, 35), "Login!")) {
StartCoroutine(LoginAccount());
}
GUI.Label(new Rect(225, 55, 290, 100), "Before Continuing you need to login or register.");
GUI.Label(new Rect(215, 102, 100, 100), "Email:");
Email = GUI.TextField (new Rect (330, 100, 150, 25), Email);
GUI.Label(new Rect(215, 150, 100, 100), "Password:");
Password = GUI.TextField (new Rect (330, 147, 150, 25), Password);
}
void CreateAccountGUI(){
GUI.Box (new Rect (210, 15, 300, 300), "Register to save progress");
if (GUI.Button (new Rect (250, 275, 105, 35), "Back")) {
currentMenu = "Login";
}
GUI.Label(new Rect(225, 55, 290, 100), "Register NOW!!!");
GUI.Label(new Rect(215, 102, 100, 100), "Email:");
CreateEmail = GUI.TextField (new Rect (330, 100, 150, 25), CreateEmail);
GUI.Label(new Rect(215, 150, 100, 100), "Password:");
CreatePassword = GUI.TextField (new Rect (330, 147, 150, 25), CreatePassword);
GUI.Label(new Rect(215, 198, 122, 100), "Confirm Password:");
ConfirmPass = GUI.TextField (new Rect (330, 194, 150, 25), ConfirmPass);
GUI.Box (new Rect (210, 15, 300, 300), "Register to save progress");
if (GUI.Button (new Rect (250, 275, 105, 35), "Back")) {
currentMenu = "Login";
}
if (GUI.Button (new Rect (370, 275, 105, 35), "Create Account")) {
if (CreatePassword == ConfirmPass){
StartCoroutine("CreateAccount");
}
else{
Debug.Log("Both Passwords are not the same");
}
}
}
IEnumerator CreateAccount(){
//this sends info to php form
WWWForm CreateAccountForm = new WWWForm ();
CreateAccountForm.AddField ("Email", CreateEmail);
CreateAccountForm.AddField ("Password", CreatePassword);
WWW CreateAccountWWW = new WWW (createAccountUrl, CreateAccountForm);
yield return CreateAccountWWW;
if (CreateAccountWWW.error != null) {
Debug.LogError ("Failed to Create Account. Is Internet On? Is URL Correct? Error Message: " + CreateAccountWWW.error);
} else {
string CreateAccountReturn = CreateAccountWWW.text;
Debug.Log("Successfully Created Account " + CreateEmail);
Application.LoadLevel("MainScene");
}
}
IEnumerator LoginAccount(){
Debug.Log ("Attempting to login...");
WWWForm Form = new WWWForm ();
Form.AddField ("Email", Email);
Form.AddField ("Password", Password);
WWW LoginAccountWWW = new WWW (loginUrl, Form);
yield return LoginAccountWWW;
if (LoginAccountWWW.error != null) {
Debug.LogError("Problem with Database. Error Message: " + LoginAccountWWW.error);
}
else {
string LogText = LoginAccountWWW.text;
Debug.Log(LogText);
string[] LogTextSplit = LogText.Split(':');
if (LogTextSplit[1] == "Success"){
Application.LoadLevel("MainScene");
}
}
}
}
When I press play from unity editor I get error: "Database Error" from #mysql_query() on $result_id.
use query string as format like this
"SELECT m.name FROM test.members WHERE name=%s OR id=%d OR sex IN (%a)", "Evil 'injection'", 'NaN', array('male', 'female', 'both', 'other', "Alien quote'man"));
I spent about a week learning and using OGLES 1.0. I realized I needed to use 2.0 for some features that I found appealing. I have been working on converting from 1.0 to 2.0 for a couple days now. I have finally hit a point where I am not getting errors (That I can find) and have a screen rendering. All I see is the clearcolor though. I have tried changing things around and reading ALOT to figure out what my problem is but I just can't find the answer :( So here I am asking you why all I see is the clearcolor. Assuming my parser is correct (it was working flawlessly for 1.0) my BufferObjects/arrays/indices are correct(they were for 1.0) my problems is in the code I am posting. Please, any ANY direction to where I need to start looking is very much appreciated. Thanks in advance.
(please excuse unused variables and methods etc)
renderer
public class TestRenderer implements Renderer {
private static final String TAG = TestRenderer.class.getSimpleName();
Cube tester;
Parser parser;
Context context;
private int mProgram;
private int muMVPMatrixHandle;
private float[] mMVPMatrix = new float[16];
private float[] mMMatrix = new float[16];
private float[] mVMatrix = new float[16];
private float[] mProjMatrix = new float[16];
private String vertexShaderCode = "attribute vec4 a_Position; "
+ "attribute vec3 a_Normal; " + "attribute vec2 a_Textcoords; "
+ "varying vec2 v_Textcoords;" + "uniform mat4 uMVPMatrix; "
+ "attribute vec4 vPosition; " + "void main(){ "
+ "v_Textcoords = a_Textcoords;"
+ " gl_Position = uMVPMatrix * vPosition; " +
"} ";
private String fragmentShaderCode = "precision mediump float; "
+ "varying vec2 v_Textcoords;" + "uniform sampler2D u_Texture; "
+ "void main(){ "
+ " gl_FragColor = texture2D(u_Texture, v_Textcoords); " + "} ";
TestRenderer(Context context) {
this.context = context;
parser = new Parser(context);
parser.parse("Turret2.obj");
tester = new Cube(parser.v, parser.f, parser.vt, parser.vtPointer,
parser.vn, parser.vnPointer, 1);
}
public static void checkGLError(String msg) {
int e = GLES20.glGetError();
if (e != GLES20.GL_NO_ERROR) {
Log.d(TAG, "GLES20 ERROR: " + msg + " " + e);
Log.d(TAG, errString(e));
}
}
public static String errString(int ec) {
switch (ec) {
case GLES20.GL_NO_ERROR:
return "No error has been recorded.";
case GLES20.GL_INVALID_ENUM:
return "An unacceptable value is specified for an enumerated argument.";
case GLES20.GL_INVALID_VALUE:
return "A numeric argument is out of range.";
case GLES20.GL_INVALID_OPERATION:
return "The specified operation is not allowed in the current state.";
case GLES20.GL_INVALID_FRAMEBUFFER_OPERATION:
return "The command is trying to render to or read from the framebuffer"
+ " while the currently bound framebuffer is not framebuffer complete (i.e."
+ " the return value from glCheckFramebufferStatus is not"
+ " GL_FRAMEBUFFER_COMPLETE).";
case GLES20.GL_OUT_OF_MEMORY:
return "There is not enough memory left to execute the command."
+ " The state of the GL is undefined, except for the state"
+ " of the error flags, after this error is recorded.";
default:
return "UNKNOW ERROR";
}
}
public void onDrawFrame(GL10 unused) {
// TODO Auto-generated method stub
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
tester.draw(mProgram);
checkGLError("onDrawFrame 0");
}
public void onSurfaceChanged(GL10 unused, int width, int height) {
GLES20.glViewport(0, 0, width, height);
float ratio = (float) width / height;
Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, .001f, 100);
muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
Matrix.setLookAtM(mVMatrix, 0, 0, 0, 0, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
}
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
mProgram = GLES20.glCreateProgram();
checkGLError("onSurfaceCreated 3");
int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
checkGLError("onSurfaceCreated 1");
int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER,
fragmentShaderCode);
GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader
// to program
checkGLError("onSurfaceCreated 5");
GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment
// shader to program
checkGLError("onSurfaceCreated 2");
GLES20.glLinkProgram(mProgram);
checkGLError("onSurfaceCreated 7");
Log.d(TAG,
"link program true/false 1 = "
+ GLES20.glGetProgramInfoLog(mProgram));
GLES20.glUseProgram(mProgram);
checkGLError("onDrawFrame 2");
checkGLError("onSurfaceCreated 8");
Bitmap bmp = BitmapFactory.decodeResource(context.getResources(),
R.drawable.turretbottom);
tester.loadTextures(context, bmp);
}
private int loadShader(int type, String shaderCode) {
int shader = GLES20.glCreateShader(type);
GLES20.glShaderSource(shader, shaderCode);
GLES20.glCompileShader(shader);
Log.d(TAG, "Shader info log = " + GLES20.glGetShaderInfoLog(shader));
return shader;
}
}
public void draw(int program) {
GLES20.glGenBuffers(4, vboIds, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[0]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, verts.length, vertBuff,
GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[1]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, textVerts.length, textBuff,
GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[2]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, normPoints.length,
normBuff, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, vboIds[3]);
GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, 2 * indexa.length,
faceBuff, GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[0]);
GLES20.glEnableVertexAttribArray(0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[1]);
GLES20.glEnableVertexAttribArray(1);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vboIds[2]);
GLES20.glEnableVertexAttribArray(2);
GLES20.glVertexAttribPointer(0, 3, GLES20.GL_FLOAT, false, 0, 0);
GLES20.glVertexAttribPointer(1, 2, GLES20.GL_FLOAT, false, 0, 0);
GLES20.glVertexAttribPointer(2, 3, GLES20.GL_FLOAT, false, 0, 0);
GLES20.glBindAttribLocation(program, 0, "a_Position");
GLES20.glBindAttribLocation(program, 1, "a_Textcoords");
GLES20.glBindAttribLocation(program, 2, "a_Normal");
GLES20.glDrawElements(GLES20.GL_TRIANGLES, indexa.length,
GLES20.GL_UNSIGNED_SHORT, 0);
GLES20.glDeleteBuffers(4, vboIds, 0);
}
You're biting off a lot at once, I might start with something simpler if you don't get anywhere (no textures, no colors, just single triangle) and build up from there when you get that working.
That said, I do see one error, in that glBindAttribLocation only takes effect after the next call to glLinkProgram, so your calls to glBindAttribLocation aren't doing anything (you need to bind location before linking shader).
Also when you compile/link a shader, you should be checking the result with glGetShaderiv(GL_COMPILE_STATUS)/glGetProgramiv(GL_LINK_STATUS). That's a better check for success/failure than just printing the info log.
I'm quite new to programming/Unity and trying to figure out how to use the OnGUI horizontal slider.
I've got three sliders range 0-100 and want a value named pointsLeft to increase/decrease when the user moves the sliders. Also the total value of the three sliders can't be over 100. I would really appreciate it if someone could help a newbie! See code for more details.
using UnityEngine;
using System.Collections;
public class Slider : MonoBehaviour {
public float sliderA = 0.0f;
public float sliderB = 0.0f;
public float sliderC = 0.0f;
public float startingPoints = 100f;
public float pointsLeft;
void Start() {
pointsLeft = startingPoints;
}
void OnGUI () {
GUI.Label(new Rect(250, 10, 100, 25), "Points Left: " + pointsLeft.ToString());
GUI.Label (new Rect (25, 25, 100, 30), "Strength: " + sliderA.ToString());
sliderA = GUI.HorizontalSlider (new Rect (25, 50, 500, 30), (int)sliderA, 0.0f, 100.0f);
GUI.Label (new Rect (25, 75, 100, 30), "Agility: " + sliderB.ToString());
sliderB = GUI.HorizontalSlider (new Rect (25, 100, 500, 30), (int)sliderB, 0.0f, 100.0f);
GUI.Label (new Rect (25, 125, 100, 30), "Intelligence: " + sliderC.ToString());
sliderC = GUI.HorizontalSlider (new Rect (25, 150, 500, 30), (int)sliderC, 0.0f, 100.0f);
/*if(sliderA < pointsLeft) {
pointsLeft = (int)pointsLeft - sliderA; //this is not doing the magic
}
*/
//decrease pointsLeft when the slider increases or increase pointsLeft if slider decreases
//store the value from each slider when all points are spent and the user pressess a button
}
}
Don't update the slider value until you are sure the slider move is valid.
Below, this code stores the new slider values in temp variables, and if the value is below the points allowed then it allows the change:
public float pointsMax = 100.0f;
public float sliderMax = 100.0f;
public float pointsLeft;
void OnGUI () {
// allow sliders to update based on user interaction
float newSliderA = GUI.HorizontalSlider(... (int)sliderA, 0.0f, sliderMax);
float newSliderB = GUI.HorizontalSlider(... (int)sliderB, 0.0f, sliderMax);
float newSliderC = GUI.HorizontalSlider(... (int)sliderC, 0.0f, sliderMax);
// only change the sliders if we have points left
if ((newSliderA + newSliderB + newSliderC) < pointsMax) {
// Update the current values for the sliders to use next time
sliderA = newSliderA;
sliderB = newSliderB;
sliderC = newSliderC;
}
// record the new points count
pointsLeft = pointsMax - (sliderA + sliderB + sliderC);
}